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 syntax and examples.
1. atom:
This predicate will return t if the argument is an atom otherwise it will return nil.
Syntax:
(atom 'element)
Example:
Lisp
;check atom or not
(write (atom 'geeks))
(terpri)
Output:
T
2. equal:
This predicate will check the given two arguments are equal or not, if equal it returns T otherwise nil.
Syntax:
(equal 'element1 'element2)
Example:
Lisp
;check equal or not
(write (equal 'geeks 'forgeeks))
(terpri)
;check equal or not
(write (equal 'python 'python))
(terpri)
Output:
NIL
T
3. eq:
This predicate will check will two arguments are identical in the case of sharing the same memory
It will return t if they are identical, otherwise nil
Syntax:
(eq 'element1 'element2)
Example:
Lisp
;check equal or not
(write (eq 'geeks 'forgeeks))
(terpri)
;check equal or not
(write (eq 45 45))
(terpri)
Output:
NIL
T
4. evenp:
This predicate will check the given number is even or not. It will return t if the number is even otherwise nil
Syntax:
(evenp element)
Example:
Lisp
;check even or not
(write (evenp 31))
(terpri)
;check even or not
(write (evenp 20))
(terpri)
Output:
NIL
T
5. oddp:
This predicate will check the given number is odd or not.
It will return t if the number is odd otherwise nil
Syntax:
(oddp element)
Example:
Lisp
;check odd or not
(write (oddp 31))
(terpri)
;check odd or not
(write (oddp 20))
(terpri)
Output:
T
NIL
6. zerop:
This predicate will check the given number is zero or not
it will return t if the number is zero otherwise nil
Syntax:
(zerop element)
Example:
Lisp
;check zero or not
(write (zerop 0))
(terpri)
;check zero or not
(write (zerop 20))
(terpri)
Output:
T
NIL
7. null:
This predicate will check the given element is nil or not, it returns T when the given element in nil otherwise NIL
Syntax:
(null element)
Example:
Lisp
;check null or not
(write (null 0))
(terpri)
;check null or not
(write (null nil))
(terpri)
Output:
NIL
T
8. listp:
It will return t if the given element is in a list otherwise nil
Syntax:
(listp element)
Example:
Lisp
;check list or not
(write (listp 0))
(terpri)
;check list or not
(write (listp '(g e e k s)))
(terpri)
Output:
NIL
T
9. numberp:
This predicate will return if the given argument is number otherwise nil
Syntax:
(numberp element)
Example:
Lisp
;check number or not
(write (numberp 67 ))
(terpri)
;check number or not
(write (numberp '(g e e k s)))
(terpri)
Output:
T
NIL
10. integerp:
This predicate will return t if it is an integer otherwise nil will return
Syntax:
(integerp element)
Example:
Lisp
;check integer or not
(write (integerp 67 ))
(terpri)
;check integer or not
(write (integerp '(g e e k s)))
(terpri)
Output:
T
NIL
11. rationalp:
This predicate will return t if the argument  is a rational number otherwise nil will return
Syntax:
(rationalp element)
Example:
Lisp
;check rational or not
(write (rationalp 67 ))
(terpri)
;check rational or not
(write (rationalp '(g e e k s)))
(terpri)
Output:
T
NIL
12. complex:
This predicate will return t if the argument  is a complex number otherwise nil will return
Syntax:
(complexp element)
Example:
Lisp
;check complex or not
(write (complexp #c( 10 30) ))
(terpri)
;check complex or not
(write (rationalp '(g e e k s)))
(terpri)
Output:
T
NIL
13. characterp:
This predicate will return t if the argument  is a character otherwise nil will return
Syntax:
(characterp element)
Example:
Lisp
;check character or not
(write (characterp 'h ))
(terpri)
;check character or not
(write (characterp '(g e e k s)))
(terpri)
Output:
NIL
NIL
14. floatp:
This predicate will return t if the argument  is an floating number otherwise nil will return
Syntax:
(floatp element)
Example:
Lisp
;check float or not
(write (floatp 56.78 ))
(terpri)
;check float or not
(write (floatp 67))
(terpri)
Output:
T
NIL
15. realp:
This predicate will check the given number is real or not. It will return t if it is real otherwise nil
Syntax:
(realp element)
Example:
Lisp
;check real or not
(write (realp 56.78 ))
(terpri)
;check real or not
(write (realp 67))
(terpri)
Output:
T
T
16. stringp:
This predicate will check the given argument is a string or not. It will return t if it is string otherwise nil
Syntax:
(stringp element)
Example:
Lisp
;check string or not
(write (stringp "heelo geeks" ))
(terpri)
;check string or not
(write (stringp 67))
(terpri)
Output:
T
NIL
17. arrayp:
This predicate will return t if the argument is an array otherwise nil.
Syntax:
(arrayp element)
Example:
Lisp
;create an array
(write (setf array1 (make-array '(10))))
(terpri)
;check array or not
(write (arrayp array1))
(terpri)
;check array or not
(write (arrayp 90))
(terpri)
Output:
#(NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL)
T
NIL
Similar Reads
Packages in LISP
Packages are a central mechanism in which a  Common Lisp is used in managing different sets of names and avoiding name collisions that may occur if multiple files contain the same variables or functions with the same name. Understanding the package system to correctly split our code across multiple
2 min read
Operators in LISP
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
5 min read
Variables in LISP
Similar to other languages, in LISP variables are named places that store a particular value, but they are not declared the way you declare variables in C++ or Java i.e you don't need to mention data-type of variables when declaring them as LISP is dynamically typed. LISP supports two types of varia
3 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
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
Tree in LISP
A tree is a non-linear hierarchical data structure that consists of nodes that are connected by edges. Tree stores data in a non-sequential manner so that operations like addition, deletion, updating, or searching could be performed in much less time than what it would take in linear data structures
5 min read
Structures in LISP
LISP, is a list processing, is a programming language widely used in working with data manipulation. Structures are used defines data types, that have the ability to combine with another data type to complete the given task. Attribute used: The defstruct attribute is used to create an instance of a
2 min read
Lists in LISP
Lists in common LISP is simply a single Linked list. In LISP, Lists are designed as a chain of records. While talking about record structures in LISP, the concept of Cons is vital. Cons in LISP is a record structure with 2 Â primary components. A cons function takes in 2 arguments and returns a new c
2 min read
Sequences in LISP
In Lisp, the ordered set of elements is represented by sequences. All the functionality we use in sequences is applied on vectors and lists which are two of the subtypes of sequences. Creating a Sequence:The generic function for creating a Sequence in Lisp is: ;The generic function for creating a Se
7 min read
Recursion in LISP
In the Lisp programming language, recursion is a commonly used technique for solving problems. Lisp is a functional programming language, which means it is well-suited to recursive solutions. In LISP, recursion is a programming technique in which a function calls itself repeatedly until a certain co
4 min read