comparison man/cl.texi @ 79398:ede12ef4dad4

(Equality Predicates): Delete `eql'. (Predicates, Naming Conventions, Top): Delete `eql'. (Common Lisp Compatibility): Delete `eql'. (Porting Common Lisp): Delete obsolete backquote info. Minor clarification about character constants. (Sequence Basics): Minor clarification.
author Richard M. Stallman <rms@gnu.org>
date Thu, 15 Nov 2007 11:55:59 +0000
parents 88224dc74061
children 02b9a9aa5b0c
comparison
equal deleted inserted replaced
79397:fd937348c9e9 79398:ede12ef4dad4
60 does assume a basic familiarity with Emacs Lisp. 60 does assume a basic familiarity with Emacs Lisp.
61 61
62 @menu 62 @menu
63 * Overview:: Installation, usage, etc. 63 * Overview:: Installation, usage, etc.
64 * Program Structure:: Arglists, `eval-when', `defalias' 64 * Program Structure:: Arglists, `eval-when', `defalias'
65 * Predicates:: `typep', `eql', and `equalp' 65 * Predicates:: `typep' and `equalp'
66 * Control Structure:: `setf', `do', `loop', etc. 66 * Control Structure:: `setf', `do', `loop', etc.
67 * Macros:: Destructuring, `define-compiler-macro' 67 * Macros:: Destructuring, `define-compiler-macro'
68 * Declarations:: `proclaim', `declare', etc. 68 * Declarations:: `proclaim', `declare', etc.
69 * Symbols:: Property lists, `gensym' 69 * Symbols:: Property lists, `gensym'
70 * Numbers:: Predicates, functions, random numbers 70 * Numbers:: Predicates, functions, random numbers
71 * Sequences:: Mapping, functions, searching, sorting 71 * Sequences:: Mapping, functions, searching, sorting
72 * Lists:: `cadr', `sublis', `member*', `assoc*', etc. 72 * Lists:: `caddr', `sublis', `member*', `assoc*', etc.
73 * Structures:: `defstruct' 73 * Structures:: `defstruct'
74 * Assertions:: `check-type', `assert', `ignore-errors'. 74 * Assertions:: `check-type', `assert', `ignore-errors'.
75 75
76 * Efficiency Concerns:: Hints and techniques 76 * Efficiency Concerns:: Hints and techniques
77 * Common Lisp Compatibility:: All known differences with Steele 77 * Common Lisp Compatibility:: All known differences with Steele
285 285
286 The following simple functions and macros are defined in @file{cl.el}; 286 The following simple functions and macros are defined in @file{cl.el};
287 they do not cause other components like @file{cl-extra} to be loaded. 287 they do not cause other components like @file{cl-extra} to be loaded.
288 288
289 @example 289 @example
290 eql floatp-safe endp 290 floatp-safe endp
291 evenp oddp plusp minusp 291 evenp oddp plusp minusp
292 caaar .. cddddr 292 caaar .. cddddr
293 list* ldiff rest first .. tenth 293 list* ldiff rest first .. tenth
294 copy-list subst mapcar* [2] 294 copy-list subst mapcar* [2]
295 adjoin [3] acons pairlis pop [4] 295 adjoin [3] acons pairlis pop [4]
698 This section describes functions for testing whether various 698 This section describes functions for testing whether various
699 facts are true or false. 699 facts are true or false.
700 700
701 @menu 701 @menu
702 * Type Predicates:: `typep', `deftype', and `coerce' 702 * Type Predicates:: `typep', `deftype', and `coerce'
703 * Equality Predicates:: `eql' and `equalp' 703 * Equality Predicates:: `equalp'
704 @end menu 704 @end menu
705 705
706 @node Type Predicates, Equality Predicates, Predicates, Predicates 706 @node Type Predicates, Equality Predicates, Predicates, Predicates
707 @section Type Predicates 707 @section Type Predicates
708 708
838 838
839 @node Equality Predicates, , Type Predicates, Predicates 839 @node Equality Predicates, , Type Predicates, Predicates
840 @section Equality Predicates 840 @section Equality Predicates
841 841
842 @noindent 842 @noindent
843 This package defines two Common Lisp predicates, @code{eql} and 843 This package defines the Common Lisp predicate @code{equalp}.
844 @code{equalp}.
845
846 @defun eql a b
847 This function is almost the same as @code{eq}, except that if @var{a}
848 and @var{b} are numbers of the same type, it compares them for numeric
849 equality (as if by @code{equal} instead of @code{eq}). This makes a
850 difference only for versions of Emacs that are compiled with
851 floating-point support. Emacs floats are allocated
852 objects just like cons cells, which means that @code{(eq 3.0 3.0)}
853 will not necessarily be true---if the two @code{3.0}s were allocated
854 separately, the pointers will be different even though the numbers are
855 the same. But @code{(eql 3.0 3.0)} will always be true.
856
857 The types of the arguments must match, so @code{(eql 3 3.0)} is
858 still false.
859
860 Note that Emacs integers are ``direct'' rather than allocated, which
861 basically means @code{(eq 3 3)} will always be true. Thus @code{eq}
862 and @code{eql} behave differently only if floating-point numbers are
863 involved, and are indistinguishable on Emacs versions that don't
864 support floats.
865
866 There is a slight inconsistency with Common Lisp in the treatment of
867 positive and negative zeros. Some machines, notably those with IEEE
868 standard arithmetic, represent @code{+0} and @code{-0} as distinct
869 values. Normally this doesn't matter because the standard specifies
870 that @code{(= 0.0 -0.0)} should always be true, and this is indeed
871 what Emacs Lisp and Common Lisp do. But the Common Lisp standard
872 states that @code{(eql 0.0 -0.0)} and @code{(equal 0.0 -0.0)} should
873 be false on IEEE-like machines; Emacs Lisp does not do this, and in
874 fact the only known way to distinguish between the two zeros in Emacs
875 Lisp is to @code{format} them and check for a minus sign.
876 @end defun
877 844
878 @defun equalp a b 845 @defun equalp a b
879 This function is a more flexible version of @code{equal}. In 846 This function is a more flexible version of @code{equal}. In
880 particular, it compares strings case-insensitively, and it compares 847 particular, it compares strings case-insensitively, and it compares
881 numbers without regard to type (so that @code{(equalp 3 3.0)} is 848 numbers without regard to type (so that @code{(equalp 3 3.0)} is
3683 arguments from which they are derived, or, if they both come from 3650 arguments from which they are derived, or, if they both come from
3684 the same sequence, in the same order as they appear in that sequence.) 3651 the same sequence, in the same order as they appear in that sequence.)
3685 The @code{:test} argument specifies a function which must return 3652 The @code{:test} argument specifies a function which must return
3686 true (non-@code{nil}) to indicate a match; instead, you may use 3653 true (non-@code{nil}) to indicate a match; instead, you may use
3687 @code{:test-not} to give a function which returns @emph{false} to 3654 @code{:test-not} to give a function which returns @emph{false} to
3688 indicate a match. The default test function is @code{:test 'eql}. 3655 indicate a match. The default test function is @code{eql}.
3689 3656
3690 Many functions which take @var{item} and @code{:test} or @code{:test-not} 3657 Many functions which take @var{item} and @code{:test} or @code{:test-not}
3691 arguments also come in @code{-if} and @code{-if-not} varieties, 3658 arguments also come in @code{-if} and @code{-if-not} varieties,
3692 where a @var{predicate} function is passed instead of @var{item}, 3659 where a @var{predicate} function is passed instead of @var{item},
3693 and sequence elements match if the predicate returns true on them 3660 and sequence elements match if the predicate returns true on them
4996 @code{defmacro*} and @code{function*} are versions of those forms 4963 @code{defmacro*} and @code{function*} are versions of those forms
4997 which understand full-featured argument lists. The @code{&whole} 4964 which understand full-featured argument lists. The @code{&whole}
4998 keyword does not work in @code{defmacro} argument lists (except 4965 keyword does not work in @code{defmacro} argument lists (except
4999 inside recursive argument lists). 4966 inside recursive argument lists).
5000 4967
5001 The @code{eql} and @code{equal} predicates do not distinguish 4968 The @code{equal} predicate does not distinguish
5002 between IEEE floating-point plus and minus zero. The @code{equalp} 4969 between IEEE floating-point plus and minus zero. The @code{equalp}
5003 predicate has several differences with Common Lisp; @pxref{Predicates}. 4970 predicate has several differences with Common Lisp; @pxref{Predicates}.
5004 4971
5005 The @code{setf} mechanism is entirely compatible, except that 4972 The @code{setf} mechanism is entirely compatible, except that
5006 setf-methods return a list of five values rather than five 4973 setf-methods return a list of five values rather than five
5215 works at the level of individual characters. For example, Common 5182 works at the level of individual characters. For example, Common
5216 Lisp implements the quote notation by a reader macro called @code{'}, 5183 Lisp implements the quote notation by a reader macro called @code{'},
5217 whereas Emacs Lisp's parser just treats quote as a special case. 5184 whereas Emacs Lisp's parser just treats quote as a special case.
5218 Some Lisp packages use reader macros to create special syntaxes 5185 Some Lisp packages use reader macros to create special syntaxes
5219 for themselves, which the Emacs parser is incapable of reading. 5186 for themselves, which the Emacs parser is incapable of reading.
5220
5221 The lack of reader macros, incidentally, is the reason behind
5222 Emacs Lisp's unusual backquote syntax. Since backquotes are
5223 implemented as a Lisp package and not built-in to the Emacs
5224 parser, they are forced to use a regular macro named @code{`}
5225 which is used with the standard function/macro call notation.
5226 5187
5227 @item 5188 @item
5228 Other syntactic features. Common Lisp provides a number of 5189 Other syntactic features. Common Lisp provides a number of
5229 notations beginning with @code{#} that the Emacs Lisp parser 5190 notations beginning with @code{#} that the Emacs Lisp parser
5230 won't understand. For example, @samp{#| ... |#} is an 5191 won't understand. For example, @samp{#| ... |#} is an
5285 @code{#(a b c)} notation in Common Lisp. To further complicate 5246 @code{#(a b c)} notation in Common Lisp. To further complicate
5286 matters, Emacs has its own @code{#(} notation for 5247 matters, Emacs has its own @code{#(} notation for
5287 something entirely different---strings with properties. 5248 something entirely different---strings with properties.
5288 5249
5289 @item 5250 @item
5290 Characters are distinct from integers in Common Lisp. The 5251 Characters are distinct from integers in Common Lisp. The notation
5291 notation for character constants is also different: @code{#\A} 5252 for character constants is also different: @code{#\A} in Common Lisp
5292 instead of @code{?A}. Also, @code{string=} and @code{string-equal} 5253 where Emacs Lisp uses @code{?A}. Also, @code{string=} and
5293 are synonyms in Emacs Lisp whereas the latter is case-insensitive 5254 @code{string-equal} are synonyms in Emacs Lisp, whereas the latter is
5294 in Common Lisp. 5255 case-insensitive in Common Lisp.
5295 5256
5296 @item 5257 @item
5297 Data types. Some Common Lisp data types do not exist in Emacs 5258 Data types. Some Common Lisp data types do not exist in Emacs
5298 Lisp. Rational numbers and complex numbers are not present, 5259 Lisp. Rational numbers and complex numbers are not present,
5299 nor are large integers (all integers are ``fixnums''). All 5260 nor are large integers (all integers are ``fixnums''). All