[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: alist and multiple values for one key
From: |
Oliver Scholz |
Subject: |
Re: alist and multiple values for one key |
Date: |
Tue, 21 Jan 2003 11:53:10 +0100 |
User-agent: |
Gnus/5.090008 (Oort Gnus v0.08) Emacs/21.3.50 (i386-mingw-nt5.1.2600) |
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)
> ==> (pine . cones)
>
> What I'd like is something that returns each value associated with
> 'pine.
If I don't want to `(require 'cl)' I use something like this:
(delq nil
(mapcar (lambda (elt)
(if (eq (car elt) 'pine) elt nil))
mtrees))
You see this (delq nil (mapcar ... in Emacs' sources at some places,
too.
Oliver
--
2 Pluviôse an 211 de la Révolution
Liberté, Egalité, Fraternité!