[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: alist and multiple values for one key
From: |
David Kastrup |
Subject: |
Re: alist and multiple values for one key |
Date: |
21 Jan 2003 12:04:19 +0100 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50 |
Oliver Scholz <alkibiades@gmx.de> writes:
> 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.
How does it benchmark against
(apply #'append (mapcar (lambda (elt) (and (eq (car elt) 'pine) (list
elt)))))
?
The latter has the advantage that you don't rip out elements that
were nil to start with, but only those that don't match the condition.
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
- alist and multiple values for one key, Norbert C., 2003/01/20
- Re: alist and multiple values for one key, Friedrich Dominicus, 2003/01/20
- Re: alist and multiple values for one key, Klaus Berndl, 2003/01/20
- Re: alist and multiple values for one key, Kai Großjohann, 2003/01/20
- Re: alist and multiple values for one key, Kai Großjohann, 2003/01/20
- Re: alist and multiple values for one key, Oliver Scholz, 2003/01/21
- Re: alist and multiple values for one key,
David Kastrup <=