unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Matthias Koeppe <mkoeppe@mail.math.uni-magdeburg.de>
Subject: Re: while break and continue
Date: Wed, 13 Aug 2003 11:27:13 +0200	[thread overview]
Message-ID: <uw5vft1aowe.fsf@saturn.math.uni-magdeburg.de> (raw)
In-Reply-To: <87znid1b4l.fsf@zip.com.au> (Kevin Ryde's message of "Thu, 14 Aug 2003 07:49:30 +1000")

Kevin Ryde <user42@zip.com.au> 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
example:

(define (rec branch breaker)
  (while #t
    (case branch
      ((1)
       (display ".")
       (breaker))    ; should break the (dynamically) outer loop
                     ; but only breaks the inner loop
      ((2)
       (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 -- http://www.math.uni-magdeburg.de/~mkoeppe


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


  reply	other threads:[~2003-08-13  9:27 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-05-30  0:00 while break and continue Kevin Ryde
2003-06-01 23:58 ` Marius Vollmer
2003-06-05  1:42   ` Kevin Ryde
2003-06-18 22:56     ` Marius Vollmer
2003-06-21 23:28       ` Kevin Ryde
2003-07-27 14:48         ` Marius Vollmer
2003-07-29  0:23           ` Kevin Ryde
2003-08-13 21:49             ` Kevin Ryde
2003-08-13  9:27               ` Matthias Koeppe [this message]
2003-08-14 23:35                 ` Kevin Ryde
2003-08-15  1:43                 ` Kevin Ryde
2003-06-06 22:31   ` Kevin Ryde
2003-06-18 22:57     ` Marius Vollmer
2003-06-20 23:56       ` Kevin Ryde

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

  List information: https://www.gnu.org/software/guile/

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

  git send-email \
    --in-reply-to=uw5vft1aowe.fsf@saturn.math.uni-magdeburg.de \
    --to=mkoeppe@mail.math.uni-magdeburg.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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).