[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Problem with position and find (cl)
From: |
Thierry Volpiatto |
Subject: |
Re: Problem with position and find (cl) |
Date: |
Fri, 20 Jun 2008 23:24:02 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) |
Florian Beck <abstraktion@t-online.de> writes:
> Marc Tfardy <m-t-o___CUT__IT@web.de> 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.
>
>
position default test is 'eq, try 'equal
,----
| ELISP> (let* ((x '((1) (2) (3) (4)))
| (y (cadr x))
| (z '(2)))
| (message "x: %s; y:%s" (position y x) (position z x :test 'equal)))
| "x: 1; y:1"
`----
--
A + Thierry
Pub key: http://pgp.mit.edu
Re: Problem with position and find (cl), Thien-Thi Nguyen, 2008/06/20