GNU Info

Info Node: (cl)Equality Predicates

(cl)Equality Predicates


Prev: Type Predicates Up: Predicates
Enter node , (file) or (file)node

Equality Predicates
===================

This package defines two Common Lisp predicates, `eql' and `equalp'.

 - Function: eql a b
     This function is almost the same as `eq', except that if A and B
     are numbers of the same type, it compares them for numeric
     equality (as if by `equal' instead of `eq').  This makes a
     difference only for versions of Emacs that are compiled with
     floating-point support.  Emacs floats are allocated objects just
     like cons cells, which means that `(eq 3.0 3.0)' will not
     necessarily be true--if the two `3.0's were allocated separately,
     the pointers will be different even though the numbers are the
     same.  But `(eql 3.0 3.0)' will always be true.

     The types of the arguments must match, so `(eql 3 3.0)' is still
     false.

     Note that Emacs integers are "direct" rather than allocated, which
     basically means `(eq 3 3)' will always be true.  Thus `eq' and
     `eql' behave differently only if floating-point numbers are
     involved, and are indistinguishable on Emacs versions that don't
     support floats.

     There is a slight inconsistency with Common Lisp in the treatment
     of positive and negative zeros.  Some machines, notably those with
     IEEE standard arithmetic, represent `+0' and `-0' as distinct
     values.  Normally this doesn't matter because the standard
     specifies that `(= 0.0 -0.0)' should always be true, and this is
     indeed what Emacs Lisp and Common Lisp do.  But the Common Lisp
     standard states that `(eql 0.0 -0.0)' and `(equal 0.0 -0.0)' should
     be false on IEEE-like machines; Emacs Lisp does not do this, and in
     fact the only known way to distinguish between the two zeros in
     Emacs Lisp is to `format' them and check for a minus sign.

 - Function: equalp a b
     This function is a more flexible version of `equal'.  In
     particular, it compares strings case-insensitively, and it compares
     numbers without regard to type (so that `(equalp 3 3.0)' is true).
     Vectors and conses are compared recursively.  All other objects
     are compared as if by `equal'.

     This function differs from Common Lisp `equalp' in several
     respects.  First, Common Lisp's `equalp' also compares
     _characters_ case-insensitively, which would be impractical in
     this package since Emacs does not distinguish between integers and
     characters.  In keeping with the idea that strings are less
     vector-like in Emacs Lisp, this package's `equalp' also will not
     compare strings against vectors of integers.

   Also note that the Common Lisp functions `member' and `assoc' use
`eql' to compare elements, whereas Emacs Lisp follows the MacLisp
tradition and uses `equal' for these two functions.  In Emacs, use
`member*' and `assoc*' to get functions which use `eql' for comparisons.


automatically generated by info2www version 1.2.2.9