From: Thierry Volpiatto <thierry.volpiatto@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Wanted: mapcar() without nils
Date: Sat, 13 Jun 2009 21:05:56 +0200 [thread overview]
Message-ID: <871vpouf6z.fsf@tux.homenetwork> (raw)
In-Reply-To: 65652541-cb7d-4c93-8baf-cd963990e57e@g1g2000yqh.googlegroups.com
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.nordlow@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
next prev parent reply other threads:[~2009-06-13 19:05 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-06-13 12:19 Wanted: mapcar() without nils Nordlöw
2009-06-13 12:47 ` Lennart Borgman
[not found] ` <mailman.562.1244897231.2239.help-gnu-emacs@gnu.org>
2009-06-13 18:24 ` Nordlöw
2009-06-13 19:05 ` Thierry Volpiatto [this message]
[not found] ` <mailman.581.1244920367.2239.help-gnu-emacs@gnu.org>
2009-06-13 19:33 ` Nordlöw
2009-06-13 19:45 ` Nordlöw
2009-06-13 19:43 ` Lennart Borgman
2009-06-13 20:02 ` Drew Adams
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=871vpouf6z.fsf@tux.homenetwork \
--to=thierry.volpiatto@gmail.com \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.