all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Tim Bradshaw <tfb@tfeb.org>
To: help-gnu-emacs@gnu.org
Subject: Re: How to cast an imperative loop into a readable recursive function ?
Date: Fri, 3 Dec 2010 09:44:47 +0000	[thread overview]
Message-ID: <idae6e$9cf$1@news.eternal-september.org> (raw)
In-Reply-To: 84a24d31-6379-4b81-ac65-b0d8642ab7da@37g2000prx.googlegroups.com

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.



  parent reply	other threads:[~2010-12-03  9:44 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-03  1:50 How to cast an imperative loop into a readable recursive function ? Katalin Sinkov
2010-12-03  2:17 ` Paul Rubin
     [not found]   ` <8a5ef1e1-aab3-47bd-80e3-081f8dc65b0e@c39g2000yqi.googlegroups.com>
     [not found]     ` <84a24d31-6379-4b81-ac65-b0d8642ab7da@37g2000prx.googlegroups.com>
2010-12-03  3:30       ` Paul Rubin
     [not found]         ` <0c1c00c1-61ef-42be-a2d3-db1ff31035e8@29g2000yqq.googlegroups.com>
2010-12-03  7:29           ` Paul Rubin
2010-12-03  9:44       ` Tim Bradshaw [this message]
2010-12-03  2:48 ` RG
2010-12-03  3:12   ` Katalin Sinkov
     [not found]     ` <7xk4jrmtmg.fsf@ruckus.brouhaha.com>
2010-12-03  3:22       ` Katalin Sinkov
     [not found]     ` <87ipzbpgft.fsf@kuiper.lan.informatimago.com>
2010-12-03  7:37       ` Katalin Sinkov

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='idae6e$9cf$1@news.eternal-september.org' \
    --to=tfb@tfeb.org \
    --cc=help-gnu-emacs@gnu.org \
    /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.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.