- LISP Tutorial
- LISP - Home
- LISP - Overview
- LISP - Environment
- LISP - Program Structure
- LISP - Basic Syntax
- LISP - Data Types
- LISP - Macros
- LISP - Variables
- LISP - Constants
- LISP - Operators
- LISP - Decisions
- LISP - Loops
- LISP - Functions
- LISP - Predicates
- LISP - Numbers
- LISP - Characters
- LISP - Arrays
- LISP - Strings
- LISP - Sequences
- LISP - Lists
- LISP - Symbols
- LISP - Vectors
- LISP - Set
- LISP - Tree
- LISP - Hash Table
- LISP - Input & Output
- LISP - File I/O
- LISP - Structures
- LISP - Packages
- LISP - Error Handling
- LISP - CLOS
- LISP Useful Resources
- Lisp - Quick Guide
- Lisp - Useful Resources
- Lisp - Discussion
LISP - Comparison Operators
Following table shows all the relational operators supported by LISP that compares between numbers. However unlike relational operators in other languages, LISP comparison operators may take more than two operands and they work on numbers only.
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 10 |
Example
Create a new source code file named main.lisp and type the following code in it.
(setq a 10) (setq b 20) (format t "~% A = B is ~a" (= a b)) (format t "~% A /= B is ~a" (/= a b)) (format t "~% A > B is ~a" (> a b)) (format t "~% A < B is ~a" (< a b)) (format t "~% A >= B is ~a" (>= a b)) (format t "~% A <= B is ~a" (<= a b)) (format t "~% Max of A and B is ~d" (max a b)) (format t "~% Min of A and B is ~d" (min a b))
When you click the Execute button, or type Ctrl+E, LISP executes it immediately and the result returned is −
A = B is NIL A /= B is T A > B is NIL A < B is T A >= B is NIL A <= B is T Max of A and B is 20 Min of A and B is 10
lisp_operators.htm
Advertisements