help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: About equality in Emacs


From: Pascal J. Bourguignon
Subject: Re: About equality in Emacs
Date: Sun, 03 Feb 2013 17:22:25 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux)

Xue Fuqiao <xfq.free@gmail.com> writes:

> In the trunk version of (info "(cl) Equality Predicates"):
>
>    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
> `memq' (or `cl-member') and `assq' (or `cl-assoc') to get functions
> which use `eql' for comparisons.
>
> I'm confused with the last sentence.  Don't `memq' and `assq' compare
> objects with `eq'?  

Perhaps.  But in Common Lisp, it would be EQL, since (eq 1 1) or (eq #\a
#\a) can return NIL. (member 1 '(1 2 3) :test (function eq)) is not
conforming in Common Lisp.

In emacs lisp, the difference between eq and eql is for floating point
numbers, where (eq 1.0 1.0) --> nil  while  (eql 1.0 1.0) --> t

In emacs-version "24.2.1":
  (memq 1 '(1 2))       --> (1 2)
  (memq 1.0 '(1.0 2.0)) --> nil 
memq uses eq, so it's no good on floating point numbers.


> Why does the manual say that they "get functions
> which use `eql' for comparisons"?

The sentence is: "In Emacs, use `memq' (or `cl-member') and `assq' (or
`cl-assoc') to get functions which use `eql' for comparisons."

The original sentence was: "In Emacs, use `member*' and `assoc*' to get
functions which use `eql' for comparisons."

The original meant that if you want to compare with eql, then instead of
using member or assoc, you would use member* and assoc*.

The new version indeed is hard to understand.  Does it mean that memq
and assq now use eql?  I'd be surprised if it did.

    New emacs:                     Old emacs:
    memq assq         ?  eq        memq assq
    member assoc         equal     member assoc
    cl-member cl-assoc   eql       member* assoc*


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
A bad day in () is better than a good day in {}.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]