[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: while break and continue

From: Kevin Ryde
Subject: Re: while break and continue
Date: Sun, 22 Jun 2003 09:28:26 +1000
User-agent: Gnus/5.090019 (Oort Gnus v0.19) Emacs/21.2 (gnu/linux)

Marius Vollmer <address@hidden> writes:
> Discourage the use of 'while' or merely 'continue' and 'break'?

Oh, well, continue and break I guess.

> I
> think, pointing in the docs of 'while' to 'do' and the other ways of
> doing loops in Scheme would be good.

Might have a go at more in the introductory para of the "while do"

> I think the value of a while loop is ill-specified anyway and we
> should always return unspecified.  What should be returned when the
> condition becomes false?  Your macro arranges to return #t, wich seems
> arbitrary.

I think I return unspecified, since there's no final value expr in the
"do" loop.  I'll make sure that's the case though.

> People who want their loop to return a specific value
> should use 'do', named 'let', or some other mechanism, I'd say.

As long as no-one has peeked at boot-9.scm and used break with a
value.  Would seem unlikely, but could perhaps make it optional, for
maximum compatibility.

I suppose a radical alternative would be to drop break and continue
completely, having never been documented (and continue not really

I simplified my code, per below.  The theory is to have only one
catch, for efficiency, and to have an inner "do" loop so that if break
and continue are not used then the catch isn't re-established on each

(define-macro (while cond . body)
  (let ((key (make-symbol "while-key")))
    `(do ((break    (lambda () (throw ',key #t)))
          (continue (lambda () (throw ',key #f))))
         ((catch ',key
                 (lambda ()
                   (do ()
                       ((not ,cond))
                 (lambda (key arg) arg))))))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]