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

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

Re: Problem with position and find (cl)


From: Florian Beck
Subject: Re: Problem with position and find (cl)
Date: Fri, 20 Jun 2008 22:14:05 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)

Marc Tfardy <address@hidden> writes:

> Marc Tfardy schrieb:
>> I try with:
>> (member '(2) '((1) (2) (3) (4)))

`member' tests the components: ›2‹ ist always equal (in the sense of »eq«) to 
›2‹

Compare:

(memq '(2) '((1) (2) (3) (4)))
(eq 2 2)
(eq '(2) '(2))

>>
>> and this gives a expectet results ((2) (3) (4)), but:
>> (find '(2) '((1) (2) (3) (4)))
>> or
>> (position '(2) '((1) (2) (3) (4)))
>>
>> returns nil. Why?

Because  the first and the second »(2)« have the same components but are
*different* lists.

> But this works:
>
> (position '(2) '((1) (2) (3) (4)) :test (lambda (x y) (eq (car x) (car
> y))))
>
> Maybe position and find (and maybe some others functions)
> can not compare lists directly?

They can, but again, the elements are not identical. Compare:

(let* ((x '((1) (2) (3) (4)))
       (y (cadr x))
       (z '(2)))
    (message "x: %s; y:%s" (position y x) (position z x)))

y ist the same object as the cadr of x, z is an entirely new object that
happens to have the same component.


>
> Marc

-- 
Florian Beck


reply via email to

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