From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Pascal J. Bourguignon" Newsgroups: gmane.emacs.help Subject: Re: I'd like to marry while and mapcar... Date: Fri, 06 Feb 2015 15:13:58 +0100 Organization: Informatimago Message-ID: <87a90rp1p5.fsf@kuiper.lan.informatimago.com> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1423232724 7182 80.91.229.3 (6 Feb 2015 14:25:24 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 6 Feb 2015 14:25:24 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Feb 06 15:25:21 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 1YJjqS-0000tG-3P for geh-help-gnu-emacs@m.gmane.org; Fri, 06 Feb 2015 15:25:20 +0100 Original-Received: from localhost ([::1]:48613 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YJjqR-0001Tz-HV for geh-help-gnu-emacs@m.gmane.org; Fri, 06 Feb 2015 09:25:19 -0500 Original-Path: usenet.stanford.edu!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 58 Original-X-Trace: individual.net U4+f8/UXSP00wU1nga7DnwxO5X+Mcu3GIUCeZHob7XyPBVF2ml Cancel-Lock: sha1:OWViOTMzMjI4MzNlMjhmZWE0YTE1OTUwNTliOWYzOWFmMDFlODkyZA== sha1:Q8+vSJ8Xx/J9OlTwPcgfgllrnhA= Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Original-Xref: usenet.stanford.edu gnu.emacs.help:210259 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:102536 Archived-At: Marcin Borkowski writes: > 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...) Nothing standard really. The technique is simple: just write what you want to use: (map-while (function get-TeX-macro-arguments) list-of-includes) How map-while is implemented is irrelevant, and an exercise left to the readers (see other posts). Well, I'm a reader too ;-) (require 'cl) (defun map-while (pred-fun list) (loop for item in list for result = (funcall pred-fun item) while result collect result)) -- __Pascal Bourguignon__ http://www.informatimago.com/ “The factory of the future will have only two employees, a man and a dog. The man will be there to feed the dog. The dog will be there to keep the man from touching the equipment.” -- Carl Bass CEO Autodesk