From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Doug Lewan Newsgroups: gmane.emacs.help Subject: RE: I'd like to marry while and mapcar... Date: Fri, 6 Feb 2015 13:44:29 +0000 Message-ID: <155DEC68569B714B86C2C7075F5EDA9892BC1BC2@DAKIYA1.pegasus.local> References: <87vbjfdwq7.fsf@wmi.amu.edu.pl> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1423230297 29860 80.91.229.3 (6 Feb 2015 13:44:57 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 6 Feb 2015 13:44:57 +0000 (UTC) To: Marcin Borkowski , Help Gnu Emacs mailing list Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Feb 06 14:44:53 2015 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1YJjDI-00044l-Rm for geh-help-gnu-emacs@m.gmane.org; Fri, 06 Feb 2015 14:44:52 +0100 Original-Received: from localhost ([::1]:48339 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YJjDI-0005Zy-DS for geh-help-gnu-emacs@m.gmane.org; Fri, 06 Feb 2015 08:44:52 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:56584) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YJjCz-0005Ux-Oo for help-gnu-emacs@gnu.org; Fri, 06 Feb 2015 08:44:38 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YJjCv-0003jx-6C for help-gnu-emacs@gnu.org; Fri, 06 Feb 2015 08:44:33 -0500 Original-Received: from webmail.shubertorg.com ([207.246.209.200]:21948 helo=livemail.shubertorg.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YJjCv-0003iU-2i for help-gnu-emacs@gnu.org; Fri, 06 Feb 2015 08:44:29 -0500 Original-Received: from dakiya1.pegasus.local ([172.16.208.201]) by DAKIYA1.pegasus.local ([172.16.208.201]) with mapi id 14.03.0123.003; Fri, 6 Feb 2015 08:44:29 -0500 Thread-Topic: I'd like to marry while and mapcar... Thread-Index: AQHQQgxyoMrrX/TbkEWgmsX0+Bu7P5zjnzFw In-Reply-To: <87vbjfdwq7.fsf@wmi.amu.edu.pl> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.0.21.202] X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 X-Received-From: 207.246.209.200 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:102532 Archived-At: There are already a few small programming paradigms for such things. (dolist (VAR LIST [RESULT]) BODY...) might do the right kind of thing for y= ou, 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)) se= ems closer. (throw) and (catch) provide another style: (catch 'foo (mapcar (lambda (e) ... (if (not (magic-test e)) (throw 'foo t))))) I hope this helps. --=20 ,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 hu= man brain. > -----Original Message----- > From: help-gnu-emacs-bounces+dougl=3Dshubertticketing.com@gnu.org > [mailto:help-gnu-emacs-bounces+dougl=3Dshubertticketing.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... >=20 > Hello Emacsers and Elispers! >=20 > 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. >=20 > 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: >=20 > (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) >=20 > 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.) >=20 > 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...) >=20 > TIA, >=20 > -- > Marcin Borkowski This email was proudly sent > http://mbork.pl from my Emacs.