help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Wanted: mapcar() without nils


From: Nordlöw
Subject: Re: Wanted: mapcar() without nils
Date: Sat, 13 Jun 2009 12:33:02 -0700 (PDT)
User-agent: G2/1.0

On Jun 13, 9:05 pm, Thierry Volpiatto <thierry.volpia...@gmail.com>
wrote:
> Hi, you can use loop: (easier)
>
> ELISP> (mapcar #'(lambda (x) (when (stringp x) x)) '("a" "b" "c" 1 2 "d" 3))
> ("a" "b" "c" nil nil "d" nil)
>
> ELISP> (loop for i in '("a" "b" "c" 1 2 "d" 3) when (stringp i) collect i)
> ("a" "b" "c" "d")
>
>
>
>
>
> Nordlöw <per.nord...@gmail.com> writes:
> > This is my mockup:
>
> > (defun extract-elements (pred seq)
> >   "Extract a copy of SEQ containing all elements fullfilling
> > PRED."
> >   (delq nil (mapcar `(lambda (elm) (when (,pred elm)) elm) seq)))
> > ;; Use: (extract-elements 'symbolp '(a b 1 2)) => '(a b)
> > ;; Use: (extract-elements 'numberp '(a b 1 2)) => '(1 2)
>
> > But why does my test-cases return '(a b 1 2) all the time? The first
> > should return (a b) and second (1 2).
> > I have tried edebugging it but because mapcar is a builtin I didn't
> > get any help that way.
>
> > /Nordlöw
>
> --
> A + Thierry Volpiatto
> Location: Saint-Cyr-Sur-Mer - France

I know the meaning of backquotes and commas to specify what should be
evaluated. But what meaning does '#' have in your example?:
> ELISP> (mapcar #'(lambda (x) (when (stringp x) x)) '("a" "b" "c" 1 2 "d" 3))

/Nordlöw


reply via email to

[Prev in Thread] Current Thread [Next in Thread]