Common LISP contains a number of equality predicates. Here are the four most commonly used:
Generally = and equal are more widely used than eq and eql.
Here are some examples involving numbers:
Suppose now we have the following variable assignments:>(= 3 3.0) T >(= 3/1 6/2) T >(eq 3 3.0) NIL >(eq 3 3) T or NIL (depending on implementation of Common LISP) >(eq 3 6/2) T >(eq 3.0 6/2) NIL >(eql 3.0 3/1) NIL >(eql 3 6/2) T >(equal 3 3) T >(equal 3 3.0) T
Then:>(setf a '(1 2 3 4)) (1 2 3 4) >(setf b '(1 2 3 4)) (1 2 3 4) >(setf c b) (1 2 3 4)
In most cases, you will want to use either = or equal, and fortunately these are the easiest to understand. Next most frequently used is eq. Eql is used by advanced programmers.>(eq a b) NIL >(eq b c) T >(equal a b) T >(equal b c) T >(eql a b) NIL >(eql b c) T >(= (first a) (first b)) T >(eq (first a) (first b)) T or NIL (depending on implementation of Common LISP) >(eql (first a) (first b)) T
© Colin Allen & Maneesh Dhagat