[Top][All Lists]

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

Re: while break and continue

From: Matthias Koeppe
Subject: Re: while break and continue
Date: Wed, 13 Aug 2003 11:27:13 +0200
User-agent: Gnus/5.090004 (Oort Gnus v0.04) Emacs/21.3.50 (sparc-sun-solaris2.8)

Kevin Ryde <address@hidden> writes:

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

I think you need a fresh catch tag for every invocation (not only for
every macro expansion site) of WHILE.  Consider this recursive

(define (rec branch breaker)
  (while #t
    (case branch
       (display ".")
       (breaker))    ; should break the (dynamically) outer loop
                     ; but only breaks the inner loop
       (rec 1 break)))))

(rec 2 (lambda () #t))

This should display one "." and return because the dynamically outer
loop (branch = 2) is broken.  But with your implementation, both loops
share the same catch tag, so only the inner loop (branch = 1) is
broken, hence the outer loop continues indefinitely.

Matthias Koeppe --

reply via email to

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