LISP Operators Comparison Operators - Lisp programming

What are LISP Comparison Operators?

The below table illustrates the relational operators supported by LISP that compares numbers.
LISP comparison operators takes more than two operands, unlike other languages.
Assume variable A holds 10 and variable B holds 20, then:

Operator
Description
Example
=
Checks if the values of the operands are all equal or not, if yes then condition becomes true.
(= A B) is not true.
/=
Checks if the values of the operands are all different or not, if values are not equal then condition becomes true.
(/= A B) is true.
>
Checks if the values of the operands are monotonically decreasing.
(> A B) is not true.
<
Checks if the values of the operands are monotonically increasing.
(< A B) is true.
>=
Checks if the value of any left operand is greater than or equal to the value of next right operand, if yes then condition becomes true.
(>= A B) is not true.
<=
Checks if the value of any left operand is less than or equal to the value of its right operand, if yes then condition becomes true.
(<= A B) is true.
max
It compares two or more arguments and returns the maximum value.
(max A B) returns 20
min
It compares two or more arguments and returns the minimum value.
(min A B) returns 20

Example

Create a new source code file named main.lisp and type the following code in it.

Click the Execute button, or type Ctrl+E, LISP executes it immediately and the result returned is:

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Lisp programming Topics