The Wayback Machine - https://web.archive.org/web/20240123092308/https://www.geeksforgeeks.org/logical-operators-in-lisp/
Open In App
Related Articles

Logical Operators in LISP

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

Common LISP supports 3 types of logical operators on Boolean Values. The arguments of these operators are evaluated conditionally, therefore they are also part of the LISP control Structure. 

The common LISP operators are listed below in the table:

Operator Syntax Description
and and number1 number2 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.
or or number1 number2 This operator takes two numbers which are evaluated left to right. If any one number evaluates to non-nil, then the value of the last number is returned. Otherwise, nil is returned.
not not number This operator takes one number and returns T(true) if the argument evaluates to NIL

Example: LISP Program that demonstrates Logical operators on numbers

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 

 

Example 2: LISP Program to demonstrate Logical operators on Boolean values

Lisp




;set value 1 to T
; set value 2 to NIL
(setq val1 T)
(setq val2 NIL)
 
;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:

NIL  
T  
NIL  
T 

Learn to code easily with our course Coding for Everyone. This course is accessible and designed for everyone, even if you're new to coding. Start today and join millions on a journey to improve your skills!

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!


Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated : 22 Oct, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials