From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: =?ISO-8859-1?Q?Nordl=F6w?= Newsgroups: gmane.emacs.help Subject: Re: Wanted: mapcar() without nils Date: Sat, 13 Jun 2009 12:33:02 -0700 (PDT) Organization: http://groups.google.com Message-ID: <0bcb89f3-ac4d-41b4-8ed6-c10301a99afa@b9g2000yqm.googlegroups.com> References: <65652541-cb7d-4c93-8baf-cd963990e57e@g1g2000yqh.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1244922048 17050 80.91.229.12 (13 Jun 2009 19:40:48 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 13 Jun 2009 19:40:48 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Jun 13 21:40:46 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1MFZ5o-0003y2-TY for geh-help-gnu-emacs@m.gmane.org; Sat, 13 Jun 2009 21:40:45 +0200 Original-Received: from localhost ([127.0.0.1]:51813 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MFZ5m-0001qX-II for geh-help-gnu-emacs@m.gmane.org; Sat, 13 Jun 2009 15:40:42 -0400 Original-Path: news.stanford.edu!newsfeed.stanford.edu!postnews.google.com!b9g2000yqm.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 43 Original-NNTP-Posting-Host: 81.170.250.228 Original-X-Trace: posting.google.com 1244921582 30823 127.0.0.1 (13 Jun 2009 19:33:02 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Sat, 13 Jun 2009 19:33:02 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: b9g2000yqm.googlegroups.com; posting-host=81.170.250.228; posting-account=ytJKAgoAAAA1tg4ScoRszebXiIldA5vg User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/531.0 (KHTML, like Gecko) Chrome/3.0.189.0 Safari/531.0,gzip(gfe),gzip(gfe) Original-Xref: news.stanford.edu gnu.emacs.help:170035 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:65263 Archived-At: On Jun 13, 9:05=A0pm, Thierry Volpiatto 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=F6w writes: > > This is my mockup: > > > (defun extract-elements (pred seq) > > =A0 "Extract a copy of SEQ containing all elements fullfilling > > PRED." > > =A0 (delq nil (mapcar `(lambda (elm) (when (,pred elm)) elm) seq))) > > ;; Use: (extract-elements 'symbolp '(a b 1 2)) =3D> '(a b) > > ;; Use: (extract-elements 'numberp '(a b 1 2)) =3D> '(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=F6w > > -- > 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=F6w