Lisp - Numeric Predicates
Lisp provides various useful numeric predicates which can be used to compare number for specific functionality.
The following table shows some of the most commonly used numeric predicates −
| Sr.No. | Predicate & Description |
|---|---|
| 1 | evenp It takes one numeric argument and returns t if the argument is even number or nil if otherwise. |
| 2 | oddp It takes one numeric argument and returns t if the argument is odd number or nil if otherwise. |
| 3 | zerop It takes one numeric argument and returns t if the argument is zero or nil if otherwise. |
| 4 | plusp It takes one numeric argument and returns t if the argument is positive if otherwise. |
| 5 | minus It takes one numeric argument and returns t if the argument is negative if otherwise. |
Example - evenp
Following code check if given number is an even number.
main.lisp
(write(evenp 100)) ; T (terpri) (write(evenp 101)) ; NIL
Output
When you execute the code, it returns the following result −
T NIL
Example - oddp
Following code check if given number is an odd number.
main.lisp
(write(oddp 100)) ; NIL (terpri) (write(oddp 101)) ; T
Output
When you execute the code, it returns the following result −
NIL T
Example - zerop
Following code check if given number is zero.
main.lisp
(write(zerop 0)) ; T (terpri) (write(zerop 101)) ; NIL
Output
When you execute the code, it returns the following result −
T NIL
Example - plusp
Following code check if given number is a positive number.
main.lisp
(write(plusp 0)) ; NIL (terpri) (write(plusp 101)) ; T (terpri) (write(plusp -101)) ; NIL
Output
When you execute the code, it returns the following result −
NIL T NIL
Example - minusp
Following code check if given number is a negative number.
main.lisp
(write(minusp 0)) ; NIL (terpri) (write(minusp 101)) ; NIL (terpri) (write(minusp -101)) ; T
Output
When you execute the code, it returns the following result −
NIL NIL T