From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Hannu Koivisto Newsgroups: gmane.emacs.help Subject: Re: alist and multiple values for one key Date: Tue, 21 Jan 2003 01:45:44 +0200 Organization: NOYB Sender: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: <87n0lvv107.fsf@lynx.ionific.com> References: <841y3720xx.fsf@lucy.is.informatik.uni-duisburg.de> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: 8bit X-Trace: main.gmane.org 1043126919 23222 80.91.224.249 (21 Jan 2003 05:28:39 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Tue, 21 Jan 2003 05:28:39 +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 18aqxi-00062D-00 for ; Tue, 21 Jan 2003 06:28:38 +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 18aqvA-00045y-01 for gnu-help-gnu-emacs@m.gmane.org; Tue, 21 Jan 2003 00:26:00 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!cyclone.bc.net!newsfeed.sovam.com!news.rosnet.ru!rosnet!news.runnet.ru!newsfeed1.funet.fi!newsfeeds.funet.fi!nntp.inet.fi!inet.fi!feeder1.news.jippii.net!feeder2.news.jippii.net!reader1.news.jippii.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 33 User-Agent: Gnus/5.090007 (Oort Gnus v0.07) Emacs/21.2 (i686-pc-linux-gnu) Cancel-Lock: sha1:fx0P4wM4k9YANvwSLlIVQXrC/4w= Original-NNTP-Posting-Host: 195.197.252.71 Original-X-Complaints-To: newsmaster@saunalahti.com Original-X-Trace: reader1.news.jippii.net 1043106345 195.197.252.71 (Tue, 21 Jan 2003 01:45:45 EET) Original-NNTP-Posting-Date: Tue, 21 Jan 2003 01:45:45 EET Original-Xref: shelby.stanford.edu gnu.emacs.help:109274 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:5798 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:5798 kai.grossjohann@uni-duisburg.de (Kai Großjohann) writes: > ncauderan@hotmail.com (Norbert C.) writes: > >> 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. > > Oh, with (require 'cl), you could do > > (remove-if-not (lambda (x) (eq (car x) KEY)) ALIST) > > Is that natural? It's short, anyway. If all your predicate does is (comparison-function (key-retriever x) key), you can use the :key and :test{,-not} parameters of plain remove*, resulting to a still shorter alternative: (remove* key alist :key #'car :test-not #'eq) But neither of these retrieve all values for a given key, which is what the OP wanted. Instead, they evaluate to alists with elements whose keys match the given key. So, something like this could be used to do what the OP wanted (loop is from the cl package as well): (loop for (key . val) in trees when (eq 'pine key) collect val) -- Hannu