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: 20 Jan 2003 17:03:09 +0100 Organization: Q Software Solutions GmbH Sender: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: <877kcz6c76.fsf@fbigm.here> References: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1043079443 12903 80.91.224.249 (20 Jan 2003 16:17:23 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Mon, 20 Jan 2003 16:17:23 +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 18aebw-0003Lg-00 for ; Mon, 20 Jan 2003 17:17:21 +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 18aeQO-0003gL-01 for gnu-help-gnu-emacs@m.gmane.org; Mon, 20 Jan 2003 11:05:24 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!newsmi-us.news.garr.it!NewsITBone-GARR!news.mailgate.org!fr.clara.net!heighliner.fr.clara.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: 26 Original-X-Trace: news.t-online.com 1043078336 01 10561 0GtYESPTSCAhOE 030120 15:58:56 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:109231 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:5755 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:5755 ncauderan@hotmail.com (Norbert C.) writes: > Hi, > > I would lile to find the "good way" to retrieve multiple values > for a given key in an alist. > > But I didn't find a natural way to do it. For example : > (setq trees '((pine . cones) (pine . acorns) (oak . acorns) (maple . > seeds))) > ==> ((pine . cones) (pine . acorns) (oak . acorns) (maple . seeds)) > (assoc 'pine trees) That does not work this way. assoc can only be used with a symbol but if you step into the list you just have other lists. 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)) Regards Friedrich