From: Thierry Volpiatto <thierry.volpiatto@gmail.com>
To: Marc Tfardy <m-t-o___CUT__IT@web.de>
Cc: help-gnu-emacs@gnu.org
Subject: Re: Problem with position and find (cl)
Date: Sat, 21 Jun 2008 14:38:32 +0200 [thread overview]
Message-ID: <87bq1v6jzr.fsf@thievol.homelinux.org> (raw)
In-Reply-To: <6c441mF3e1foaU1@mid.individual.net> (Marc Tfardy's message of "Sat, 21 Jun 2008 12:38:43 +0200")
Marc Tfardy <m-t-o___CUT__IT@web.de> writes:
> Marc Tfardy schrieb:
>> Thierry Volpiatto schrieb:
>>> 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))))
>>>>>
>>
>>> 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)
> or:
> (defalias 'find-all 'remove-if-not)
>
> (a propos - what is the right method?) - it looks good and
> works like expected.
Is it something like that you are looking for ?
,----
| ELISP> (setq A '((2 "a" byte)
| (3.2 "b" float)
| (4 "c" byte)
| (6 "d" int)
| (8 "e" byte)))
| ((2 "a" byte)
| (3.2 "b" float)
| (4 "c" byte)
| (6 "d" int)
| (8 "e" byte))
|
| ELISP> (defun find-all (item lis)
| (let ((temp-list nil))
| (dolist (x lis)
| (when (equal (nth 2 x) item)
| (push x temp-list)))
| temp-list))
| find-all
| ELISP> (find-all 'byte A)
| ((8 "e" byte)
| (4 "c" byte)
| (2 "a" byte))
`----
--
A + Thierry
Pub key: http://pgp.mit.edu
next prev parent reply other threads:[~2008-06-21 12:38 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-20 18:30 Problem with position and find (cl) Marc Tfardy
2008-06-20 19:58 ` Marc Tfardy
2008-06-20 20:14 ` Florian Beck
2008-06-20 21:24 ` Thierry Volpiatto
[not found] ` <mailman.13619.1213996704.18990.help-gnu-emacs@gnu.org>
2008-06-20 23:14 ` Florian Beck
2008-06-21 2:04 ` Barry Margolin
2008-06-21 4:31 ` Florian Beck
2008-06-21 4:57 ` Thierry Volpiatto
2008-06-21 10:07 ` Marc Tfardy
2008-06-21 10:38 ` Marc Tfardy
2008-06-21 12:38 ` Thierry Volpiatto [this message]
2008-06-20 21:16 ` Thien-Thi Nguyen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87bq1v6jzr.fsf@thievol.homelinux.org \
--to=thierry.volpiatto@gmail.com \
--cc=help-gnu-emacs@gnu.org \
--cc=m-t-o___CUT__IT@web.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).