[Top][All Lists]

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

Re: Problem with position and find (cl)

From: Marc Tfardy
Subject: Re: Problem with position and find (cl)
Date: Sat, 21 Jun 2008 12:38:43 +0200
User-agent: Thunderbird (Windows/20080421)

Marc Tfardy schrieb:
Thierry Volpiatto schrieb:
Florian Beck <address@hidden> writes:

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‹


(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)))
(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

position default test is 'eq, try 'equal

Thanks! It works with equal. But I have another problem.
find (and find-if) returns only first match. Is there another
function that returns all matched elements. Some example:

(find-if-all (lambda (x) (if (eq (nth 2 x) 'byte) t nil)) '((1.1 "x" int) (2.2 "y" byte) (3.3 "q" int) (4.4 "b" byte) (5.5 "a" float)))

should returns:
((2.2 "y" byte) (4.4 "b" byte))

I found in cl-*.el nothing like this. Any hints?

I found some "strange" solution:

(remove-if-not (lambda (x) (if (eq (nth 2 x) 'byte) t nil)) '((1.1 "x" int) (2.2 "y" byte) (3.3 "q" int) (4.4 "b" byte) (5.5 "a" float)))

but with:
(fset 'find-all 'remove-if-not)
(defalias 'find-all 'remove-if-not)

(a propos - what is the right method?) - it looks good and
works like expected.


reply via email to

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