Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • DSA
  • Practice Problems
  • Python
  • C
  • C++
  • Java
  • Courses
  • Machine Learning
  • DevOps
  • Web Development
  • System Design
  • Aptitude
  • Projects
Open In App
Next Article:
Arithmetic Operators in LISP
Next article icon

Operators in LISP

Last Updated : 29 Oct, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report

Operators are the foundation of any programming language. Thus the functionality of the LISP programming language is incomplete without the use of operators. We can define operators as symbols that help us to perform specific mathematical and logical computations on operands. In other words, we can say that an operator operates the operands. 

Different types of Operators in LISP

  • Arithmetic Operators
  • Comparison Operators
  • Logical Operators
  • Bitwise Operators

Arithmetic Operator:

Arithmetic operators are used to performing mathematical operations like addition, subtraction, multiplication, and division.

Operator Description Syntax
Addition Operator(+)Add the two numbers(+ num1 num2)
Subtraction Operator(-) Subtract the second number from the first number(- num1 num2)
Multiplication(*)Multiply two numbers(* num1 num2)
Division(/)Divide the two numbers(/ num1 num2)
Modulus(mod) Get the remainder of two numbers(MOD num1 num2)
Increment(incf)Increment number by given value(incf num1 num2)
Decrement(decf)Decrement number by given value(decf num1 num2)

Example: Arithmetic Operators 

Lisp
;set value 1 to 300 ; set value 2 to 600 (setq val1 300) (setq val2 600)  ;addition operation (print (+ val1 val2))  ;subtraction operation (print (- val1 val2))  ;multiplication operation (print (* val1 val2))  ;division operation (print (/ val1 val2))  ;modulus operation (print (MOD val1 val2))  ;increment a by 10 (print (incf val1 val2))  ;decrement b by 20 (print (decf val1 val2)) 

Output :

900    -300    180000    1/2    300    900    300 

Comparison Operator:

These operators are used to compare numbers by taking two or more operands.

Operator Description Syntax
=This operator checks if the values of the operands are all equal or not, if yes, will return T(True) otherwise NIL(= num1 num2)
/=This operator checks if the values of the operands are not equal, if yes, will return NIL otherwise T (True)(/= num1 num2)
>This operator checks if the values of the operand 1 are greater than operand 2, if yes then it returns True, otherwise NIL(> num1 num2)
<This operator checks if the values of the operand 1 are less than operand 2, if yes then it returns True, otherwise NIL(< num1 num2)
>=This operator checks if the values of the operand 1 are greater than or equal to  operand 2, if yes then it returns True, otherwise NIL(>= num1 num2)
<=This operator checks if the values of the operand 1 are less than or equal to  operand 2, if yes then it returns True, otherwise NIL(<= num1 num2)  
maxThis operator returns the maximum value.(max num1 num2) 
minThis operator returns the minimum value.(min num1 num2)

Example: Comparison Operators

Lisp
;set value 1 to 100 ; set value 2 to 200 (setq val1 100) (setq val2 200)  ;check val1 is equal to val2 or not (print (= val1 val2))  ;check val1 is not equal to val2 or not (print (/= val1 val2))  ;check val1 is greater than val2 or not (print (> val1 val2))  ;check val1 is less than val2 or not (print (< val1 val2))  ;check val1 is greater than or equal to val2 or not (print (>= val1 val2))  ;check val1 is less than or equal to val2 or not (print (<= val1 val2))  ;get maximum number among val1 and val2 (print (max val1 val2))  ;get minimum number among val1 and val2 (print (min val1 val2)) 

Output:

NIL    T    NIL    T    NIL    T    200    100 

Logical Operator:

Common LISP supports 3 types of logical operators on Boolean Values

Operator Description Syntax 
and

This operator takes two numbers which are evaluated left to right. If all numbers evaluate to non-nil, then the value of the last number is returned.

 Otherwise, nil is returned.

(and num1 num2)
orThis operator takes two numbers which are evaluated left to right. If any number evaluates to non-nil, then the value of the last number is returned. Otherwise, nil is returned.(or num1 num2)
notThis operator takes one number and returns T(true) if the argument evaluates to NIL(not num1)

Example of Logical Operators

Lisp
;set value 1 to 50 ; set value 2 to 50 (setq val1 50) (setq val2 50)  ;and operator (print (and val1 val2))  ;or operator (print (or val1 val2))  ;not operator with value1 (print (not val1))  ;not operator with value2 (print (not val2)) 

Output:

50    50    NIL    NIL 

Bitwise Operator:

These operators are used to perform the manipulation of individual bits of a number.

Operator Description Syntax
logandThe operator returns bitwise logical AND of two numbers (logand num1 num2)
logiorThe operator returns bitwise Inclusive OR of two numbers(logior num1 num2)
logxorThe operator returns bitwise Exclusive OR of two numbers(logxor num1 num2)
lognorThe operator returns bitwise NOT of two numbers(lognor num1 num2)
logeqvThe operator returns bitwise Exclusive NOR of two numbers(logeqv num1 num2)
logcountThe operator returns the number of ones in the binary representation of an integer(logcount num1)
ashShifts the bits to the left if the count is positive else to the right(ash num count)

Example: Bitwise Operators

Lisp
;set value of variable val1 to 10 (setq val1 10) ;set value of variable val2 to 5 (setq val2 5)  ;; logand operator (print (logand val1 val2))  ;; logior operator (print (logior val1 val2))  ;; logxor operator (print (logxor val1 val2))  ;; lognor operator (print (lognor val1 val2))  ;; logeqv operator (print (logeqv val1 val2))  ;; logcount operator (print (logcount val2))  ; arithmetic left shift (print (ash val1 val2))     ; arithmetic right shift  (print (ash val1 (- val2)))  

Output :

0   15   15   -16   -16   2   320   0 

Next Article
Arithmetic Operators in LISP
author
aniruddhashriwant
Improve
Article Tags :
  • LISP
  • Operators
  • LISP-Basics
Practice Tags :
  • Operators

Similar Reads

  • Bitwise Operators in LISP
    In this article, we will discuss the Bitwise operators in LISP. These operators are used to perform the manipulation of individual bits of a number. The truth table for bitwise AND, NAND, OR, XOR, NOR, & XNOR:  aba and b a nand ba or b a xor b a nor b a xnor b00010011010111001110100110011100 Dif
    4 min read
  • Vectors in LISP
    In this article, we will discuss Vectors in LISP. Vectors in LISP are one-dimensional arrays which are also known as sequences. We can create a vector using vector function and # symbol Syntax: variable_name(vector element1 element2 ... element n) or variable_name #(element1 element2 ... element n)
    2 min read
  • Arithmetic Operators in LISP
    Arithmetic operators are used to perform mathematical operations like addition, subtraction, multiplication, and division. There are 7 arithmetic operators in LISP that are listed in the below table: OperatorSyntaxDescriptionAddition Operator(+)+ num1 num2Add the two numbersSubtraction Operator(-)-
    2 min read
  • Comparison Operators in LISP
    In this article, we will discuss the comparison operators in LISP. These operators are used to compare numbers by taking two or more operands. Note: This will work only on numbers, Different comparison operators are:OperatorSyntaxNameDescription== operand1 operand2equal toThis operator checks if the
    4 min read
  • Sets in LISP
    A set is an unordered collection of items. A set is just like other data structures. In C++ we have a similar data structure called a hash map. Common lisp does not provide a built-in set data type, but it provides a number of functions that allow set operations to be performed onto a list. Using th
    7 min read
  • Predicates in LISP
    In this article, we will discuss predicates. Predicates are similar to functions that will be used to test their arguments for conditions. They will return NIL if the conditions are not met, if the conditions are met, they will return T. Types of predicates: Below is a list of major Predicates with
    5 min read
  • ES6 Operators
    An expression is a special kind of statement that evaluates to a value. Every expression consists of Operands: Represents the data.Operator: which performs certain operations on operands. Consider the following expression - 2 / 3, in the expression, 2 and 3 are operands and the symbol /is the operat
    7 min read
  • || operator in Java
    || is a type of Logical Operator and is read as "OR OR" or "Logical OR". This operator is used to perform "logical OR" operation, i.e. the function similar to OR gate in digital electronics. One thing to keep in mind is the second condition is not evaluated if the first one is true, i.e. it has a sh
    1 min read
  • Loops in LISP
    Loops allow executing a set of instructions repeatedly while some condition is true. LISP provides the following types of loops: 1. dotimes loop: The dotimes loop allows executing instructions for a fixed number of times.Syntax:  (dotimes( variableName numberOfIterations ) ( expressions )) Where, va
    4 min read
  • C++ Logical Operators
    In C++ programming languages, logical operators are symbols that allow you to combine or modify conditions to make logical evaluations. They are used to perform logical operations on boolean values (true or false). In C++, there are three logical operators: Table of Content Logical AND Operator (
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences