From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Thierry Volpiatto Newsgroups: gmane.emacs.help Subject: Re: Problem with position and find (cl) Date: Sat, 21 Jun 2008 14:38:32 +0200 Message-ID: <87bq1v6jzr.fsf@thievol.homelinux.org> References: <6c2bb4F3dibi5U1@mid.individual.net> <6c2gf4F3eltftU1@mid.individual.net> <87hcbng8z6.fsf@sophokles.streitblatt.de> <6c4268F3eh5teU1@mid.individual.net> <6c441mF3e1foaU1@mid.individual.net> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1214051657 17418 80.91.229.12 (21 Jun 2008 12:34:17 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 21 Jun 2008 12:34:17 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Marc Tfardy Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Jun 21 14:35:01 2008 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1KA2J3-00086s-1o for geh-help-gnu-emacs@m.gmane.org; Sat, 21 Jun 2008 14:35:01 +0200 Original-Received: from localhost ([127.0.0.1]:38222 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KA2IE-0007JC-3L for geh-help-gnu-emacs@m.gmane.org; Sat, 21 Jun 2008 08:34:10 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KA2Gt-0006aV-Ae for help-gnu-emacs@gnu.org; Sat, 21 Jun 2008 08:32:47 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KA2Gr-0006Yq-6o for help-gnu-emacs@gnu.org; Sat, 21 Jun 2008 08:32:46 -0400 Original-Received: from [199.232.76.173] (port=60517 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KA2Gr-0006Yd-0l for help-gnu-emacs@gnu.org; Sat, 21 Jun 2008 08:32:45 -0400 Original-Received: from rv-out-0708.google.com ([209.85.198.242]:18966) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KA2Gq-00083q-JD for help-gnu-emacs@gnu.org; Sat, 21 Jun 2008 08:32:44 -0400 Original-Received: by rv-out-0708.google.com with SMTP id k29so8230766rvb.6 for ; Sat, 21 Jun 2008 05:32:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:cc:subject:references :date:in-reply-to:message-id:user-agent:mime-version:content-type :content-transfer-encoding; bh=s0YkCdtrLnETDft+lo40keoCMk7tyVWhKWSnfTxjlus=; b=QkQgZF9zb0dKoohhpllI7Ju28AMDBVkZkBniPEAmSVNAjz1XwUYewmHvuvBGb/WU56 ttaTFjc4VgNdLK7uAmI6APDLtMoWAoS+GB9H6NFb54n1Zng7jctFUSkKkaNsnYWo3VSQ a/Fpz6IveuJOFLaNGcpIVG3Pu2eNi/x7pbKXI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-type:content-transfer-encoding; b=X/OJ6etrQljvUCpZF//Zpbi/CGdxHiGYW8vHMkj8myGYTBu7/ZLcWnmnmollJV9+m3 lgXptfdIT+dR7x2Cmyo0RsQ9jFXHP68Pn/Dp3blWK25XJBoe8EdxViLSZCaQomhZZLp2 lMUwGSyquev/12Ou7skFr8TPBWrWbEr2ABXws= Original-Received: by 10.140.203.9 with SMTP id a9mr9216805rvg.203.1214051563553; Sat, 21 Jun 2008 05:32:43 -0700 (PDT) Original-Received: from thievol.homelinux.org ( [77.197.77.55]) by mx.google.com with ESMTPS id 7sm5345437wrl.41.2008.06.21.05.32.41 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sat, 21 Jun 2008 05:32:42 -0700 (PDT) In-Reply-To: <6c441mF3e1foaU1@mid.individual.net> (Marc Tfardy's message of "Sat, 21 Jun 2008 12:38:43 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 2) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:55025 Archived-At: Marc Tfardy writes: > Marc Tfardy schrieb: >> Thierry Volpiatto schrieb: >>> Florian Beck writes: >>> >>>> Marc Tfardy writes: >>>> >>>>> Marc Tfardy schrieb: >>>>>> I try with: >>>>>> (member '(2) '((1) (2) (3) (4))) >>>> `member' tests the components: =E2=80=BA2=E2=80=B9 ist always equal (i= n the sense >>>> of =C2=BBeq=C2=AB) to =E2=80=BA2=E2=80=B9 >>>> >>>> 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 =C2=BB(2)=C2=AB have the same compon= ents 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)) |=20 | 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)) `---- --=20 A + Thierry Pub key: http://pgp.mit.edu