From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Friedrich Dominicus Newsgroups: gmane.emacs.help Subject: Re: alist and multiple values for one key Date: 21 Jan 2003 07:57:56 +0100 Organization: Q Software Solutions GmbH Sender: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: <87el77f0qz.fsf@fbigm.here> References: <877kcz6c76.fsf@fbigm.here> <87iswjv0mh.fsf@lynx.ionific.com> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1043132396 4113 80.91.224.249 (21 Jan 2003 06:59:56 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Tue, 21 Jan 2003 06:59:56 +0000 (UTC) Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 18asNn-00013s-00 for ; Tue, 21 Jan 2003 07:59:39 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 18asKV-0002Cv-07 for gnu-help-gnu-emacs@m.gmane.org; Tue, 21 Jan 2003 01:56:15 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!canoe.uoregon.edu!arclight.uoregon.edu!newsfeed.mathworks.com!news.tele.dk!news.tele.dk!small.news.tele.dk!eusc.inter.net!newsfeed01.sul.t-online.de!newsmm00.sul.t-online.com!t-online.de!news.t-online.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 46 Original-X-Trace: news.t-online.com 1043132012 06 4076 f1MYEsWSLAkTj 030121 06:53:32 Original-X-Complaints-To: abuse@t-online.com X-Sender: 320004655587-0001@t-dialin.net User-Agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Native Windows TTY Support) Original-Xref: shelby.stanford.edu gnu.emacs.help:109282 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:5806 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:5806 Hannu Koivisto writes: > Friedrich Dominicus writes: > > > This code will work for the given data: > > (defun collect-if (pred list) > > (mapcar #'(lambda (el) (when (funcall pred el) el)) list)) > > > > you can call it with > > (collect-if #'(lambda (item) (eq (car item) 'pine)) trees) > > > > ((pine . cones) (pine . acorns)) > > I'm afraid that is not what your example expression evaluates to. > Did you try it? Yes and unfortunatly did I get those results, which I know now are not correct after your posting and re-thinking and re-trying it. However what I wanted to write was (defun find-all-matching (pred list) (delete-if (lambda (item) (not (funcall pred item))) list)) But this won't work in Emacs Lisp but this (according to posting some days ago: (defun find-all-matching (pred list) (delete-if `(lambda (item) (not (,pred item))) list)) and indeed with list I got (setf ttree '((pine . p1) (pine . p2) (oak . p3) (oak . p4) (pine . p4))) (find-all-matching #'(lambda (item) (eq (car item) 'pine)) ttree) ((pine . p1) (pine . p2) (pine . p4)) This is what I wanted to get. But it's nevertheless wrong because it is not what the original author wanted. You are right. He just wanted the values and there your example with loop works as it should. Thanks for pointing that out to me. Friedrich