Subject: Re: loops with MzScheme
From: (Rob Warnock)
Date: 1999/12/02
Newsgroups: comp.lang.scheme
Message-ID: <825jma$>
Alex Krycek <> wrote:
| Is there any way to program a while or do..while loop with MzScheme?

Well, you *can*, using macros, but given that the standard Scheme
"do" with no iteration variables:

	(do () (TEST) BODY...)

is exactly the same as:

	(while TEST BODY...)

I usually don't bother with "while" per se. Besides, you almost
always need local iteration variables in a loop, and "do" handles
that for you nicely.

Likewise, "do BODY... while TEST" can be written in standard
Scheme as:

	(let loop ()
	  (when TEST (loop)))

I usually don't bother with "do-while", either.  Though YMMV...


p.s. But if you really *insist* on "while" in MzScheme, try this:

	(define-macro while
	  (lambda (test . body)
	    `(do () (,test) ,@body)))

Rob Warnock, 8L-846
Applied Networking
Silicon Graphics, Inc.		Phone: 650-933-1673
1600 Amphitheatre Pkwy.		FAX: 650-933-0511
Mountain View, CA  94043	PP-ASEL-IA