all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Oliver Scholz <alkibiades@gmx.de>
Subject: Re: tail recursion hack in Emacs Lisp?
Date: Fri, 16 Jul 2004 19:37:54 +0200	[thread overview]
Message-ID: <un01z4zv1.fsf@ID-87814.user.uni-berlin.de> (raw)
In-Reply-To: jwvvfgnhp3k.fsf-monnier+gnu.emacs.help@gnu.org

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> So my question is: Can anybody think of a case where this approach
>> would break?
>
> I have another question: why is it better than CL's `do' ?

Huh?  You mean like:

(do ((n 10 (1- n))
     (r 1 (* n r)))
    ((= n 1) r))

I had no intention to suggest that it were better. iterate/named
let is just different. Personally I find `do' hard to read, but
that might be a matter of taste.

I used `fact' just because it is the classical example. I can't
think of a really good example right now, exept maybe this:

(defun my-flatten-list (lst)
  (iterate walk-list ((lst lst)
		      (acc nil)
		      (stk nil))
    (if (null lst)
	(if (null stk)
	    (nreverse acc)
	  (walk-list stk acc nil))
      (if (listp (car lst))
	  (walk-list (car lst)
		     acc
		     (if (null (cdr lst))
			 stk
		       (cons (cdr lst)
			     stk)))
	(walk-list (cdr lst)
		   (cons (car lst) acc)
		   stk)))))

There might be better examples. To quote the CMU CL manual: "The
main advantage of using iterate over do is that iterate naturally
allows stepping to be done differently depending on conditionals
in the body of the loop."

    Oliver
-- 
29 Messidor an 212 de la Révolution
Liberté, Egalité, Fraternité!

      reply	other threads:[~2004-07-16 17:37 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-07-16 15:07 tail recursion hack in Emacs Lisp? Oliver Scholz
2004-07-16 16:23 ` Oliver Scholz
2004-07-16 16:42   ` Oliver Scholz
2004-07-16 16:53   ` Stefan Monnier
2004-07-16 17:37     ` Oliver Scholz [this message]

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=un01z4zv1.fsf@ID-87814.user.uni-berlin.de \
    --to=alkibiades@gmx.de \
    /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.