From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tim Bradshaw Newsgroups: gmane.emacs.help Subject: Re: How to cast an imperative loop into a readable recursive function ? Date: Fri, 3 Dec 2010 09:44:47 +0000 Organization: A noiseless patient Spider Message-ID: References: <7xmxontxan.fsf@ruckus.brouhaha.com> <8a5ef1e1-aab3-47bd-80e3-081f8dc65b0e@c39g2000yqi.googlegroups.com> <84a24d31-6379-4b81-ac65-b0d8642ab7da@37g2000prx.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Trace: dough.gmane.org 1291956007 10054 80.91.229.12 (10 Dec 2010 04:40:07 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 10 Dec 2010 04:40:07 +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 Dec 10 05:40:03 2010 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.69) (envelope-from ) id 1PQum3-0001cR-FU for geh-help-gnu-emacs@m.gmane.org; Fri, 10 Dec 2010 05:40:03 +0100 Original-Received: from localhost ([127.0.0.1]:58550 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PQugv-0000V1-Vf for geh-help-gnu-emacs@m.gmane.org; Thu, 09 Dec 2010 23:34:46 -0500 Original-Path: usenet.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!news2.euro.net!feeder.news-service.com!85.214.198.2.MISMATCH!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail Original-Newsgroups: comp.lang.lisp,gnu.emacs.help,comp.emacs Original-Lines: 41 Injection-Info: mx03.eternal-september.org; posting-host="NheRzlb7ZUKdUyJixEcU6w"; logging-data="9615"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+WG/k40lzLCrLboCdoO8Nn" User-Agent: Unison/2.1.3 Cancel-Lock: sha1:Mue4LNJBheSo9cRZJWCP0p4WR4s= Original-Xref: usenet.stanford.edu comp.lang.lisp:296058 gnu.emacs.help:182805 comp.emacs:100896 X-Mailman-Approved-At: Thu, 09 Dec 2010 20:23:40 -0500 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:77330 Archived-At: On 2010-12-03 03:19:43 +0000, Katalin Sinkov said: > your iterate is again a loop, ie a non-functional construct Is it? Consider this form: (for (i 0 100) (print i)) This is iterative, right, I mean obviously. Except here's the definition of FOR: (defmacro for ((var min max) &body decls-and-forms) (let ((maxn (make-symbol "MAX")) (nextn (make-symbol "NEXT-1"))) `(let ((,maxn ,max)) (labels ((,nextn (,var) (when (= ,var ,maxn) (return-from ,nextn ,maxn)) (let ((,var ,var)) ,@decls-and-forms) (,nextn (1+ ,var))) (next () (,nextn (1+ ,var)))) (,nextn ,min))))) There seems to be no iteration there, and expanding (and renaming gensyms to make it clearer): (let ((max 100)) (labels ((next-1 (i) (when (= i max) (return-from next-1 max)) (let ((i i)) (print i)) (next-1 (1+ i))) (next () (next-1 (1+ i)))) (next-1 0))) No iteration there.