From: Doug Lewan <dougl@shubertticketing.com>
To: Marcin Borkowski <mbork@wmi.amu.edu.pl>,
Help Gnu Emacs mailing list <help-gnu-emacs@gnu.org>
Subject: RE: I'd like to marry while and mapcar...
Date: Fri, 6 Feb 2015 13:44:29 +0000 [thread overview]
Message-ID: <155DEC68569B714B86C2C7075F5EDA9892BC1BC2@DAKIYA1.pegasus.local> (raw)
In-Reply-To: <87vbjfdwq7.fsf@wmi.amu.edu.pl>
There are already a few small programming paradigms for such things.
(dolist (VAR LIST [RESULT]) BODY...) might do the right kind of thing for you, but it never feels lisp-ish to me. And on a long list you might not get the efficiency you expect.
(while (and magic-condition the-list) ... (setq the-list (cdr the-list)) seems closer.
(throw) and (catch) provide another style:
(catch 'foo
(mapcar (lambda (e)
...
(if (not (magic-test e))
(throw 'foo t)))))
I hope this helps.
--
,Doug
Douglas Lewan
Shubert Ticketing
(201) 489-8600 ext 224 or ext 4335
The human brain is the most complex thing known to man, according to the human brain.
> -----Original Message-----
> From: help-gnu-emacs-bounces+dougl=shubertticketing.com@gnu.org
> [mailto:help-gnu-emacs-bounces+dougl=shubertticketing.com@gnu.org] On
> Behalf Of Marcin Borkowski
> Sent: Friday, 2015 February 06 07:57
> To: Help Gnu Emacs mailing list
> Subject: I'd like to marry while and mapcar...
>
> Hello Emacsers and Elispers!
>
> What I'd need is kind of a marriage of while and mapcar: I'd like to
> run
> some function until it returns nil and make a list of all results it
> gives back until then.
>
> Mu use case is that I'm getting some info from a LaTeX file. For
> instance, assume that I want to make a list of all files \include'd by
> a LaTeX document. I've written a function `get-TeX-macro-arguments'
> which finds the next occurence of a given TeX command, moves point past
> it and returns its arguments; if it does not find any such occurrence,
> it returns nil. So I can say something like this:
>
> (let (current-include (list-of-includes ()))
> (while (setq current-include (get-TeX-macro-arguments "include"))
> (setq list-of-includes (append list-of-includes current-include)))
> list-of-includes)
>
> This, however, looks a bit, let's say, Fortran-ish;-); I'm after a more
> Lispy way. (Of course, one step would be to use anaphoric while, but
> that doesn't help my main problem of ditching list-of-includes.)
>
> Yes, I know, I have too much time on my hands, and I bother about
> style.
> But I'm also curious whether there is any "standard" way, or whether
> I should indeed wrap something like the above code in a macro, or
> something. (Or maybe just don't care...)
>
> TIA,
>
> --
> Marcin Borkowski This email was proudly sent
> http://mbork.pl from my Emacs.
next prev parent reply other threads:[~2015-02-06 13:44 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-06 12:56 I'd like to marry while and mapcar Marcin Borkowski
2015-02-06 13:18 ` Rasmus
2015-02-06 13:53 ` Marcin Borkowski
2015-02-06 14:14 ` Rasmus
2015-02-06 13:36 ` Eli Zaretskii
2015-02-06 13:50 ` Marcin Borkowski
2015-02-06 13:44 ` Doug Lewan [this message]
[not found] ` <mailman.19396.1423229779.1147.help-gnu-emacs@gnu.org>
2015-02-06 16:25 ` Barry Margolin
2015-02-06 16:52 ` Pascal J. Bourguignon
2015-02-06 22:49 ` Drew Adams
2015-02-07 21:09 ` Robert Thorpe
2015-02-07 23:37 ` Thien-Thi Nguyen
[not found] ` <mailman.19494.1423352465.1147.help-gnu-emacs@gnu.org>
2015-02-08 0:28 ` Emanuel Berg
[not found] <mailman.19392.1423227427.1147.help-gnu-emacs@gnu.org>
2015-02-06 14:13 ` Pascal J. Bourguignon
2015-02-06 14:54 ` Joost Kremers
2015-02-06 17:47 ` Joost Kremers
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=155DEC68569B714B86C2C7075F5EDA9892BC1BC2@DAKIYA1.pegasus.local \
--to=dougl@shubertticketing.com \
--cc=help-gnu-emacs@gnu.org \
--cc=mbork@wmi.amu.edu.pl \
/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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).