[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: alist and multiple values for one key
From: |
Friedrich Dominicus |
Subject: |
Re: alist and multiple values for one key |
Date: |
21 Jan 2003 07:30:12 +0100 |
User-agent: |
Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Native Windows TTY Support) |
Hannu Koivisto <azure@iki.fi> writes:
> Friedrich Dominicus <frido@q-software-solutions.com> 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 I tried it. I can not see why mapcan should be used here. I'm
consing up a list if the predicate function yields true. So mapcar is
the right choice.
What I originally wanted was:
(defun find-all-matching (pred list)
(delete-if #'(lambda (item) (not (funcall pred item))) list))
but that won't work with Emacs Lisp but this will:
(defun find-all-matching (pred list)
(delete-if `(lambda (item) (not (,pred item))) list))
So I suggest you tell me why mapcar is not the proper
function to use.
Regards
Friedrich
> Learn about mapcan
if you want to get your code
> right using one of the map... functions. Of course, to return
> just the values as requested by the OP you will need other changes
> as well.
>
> --
> Hannu
- 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