From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Kevin Ryde Newsgroups: gmane.lisp.guile.devel Subject: Re: while break and continue Date: Sun, 22 Jun 2003 09:28:26 +1000 Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Message-ID: <87fzm3m2n9.fsf@zip.com.au> References: <87isrtmhfw.fsf@zip.com.au> <87he79ic44.fsf@zagadka.ping.de> <878yshe1ux.fsf@zip.com.au> <87n0gf0zbc.fsf@zagadka.ping.de> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1056238178 19210 80.91.224.249 (21 Jun 2003 23:29:38 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Sat, 21 Jun 2003 23:29:38 +0000 (UTC) Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Sun Jun 22 01:29:37 2003 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 19Trnc-0004zb-00 for ; Sun, 22 Jun 2003 01:29:36 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.20) id 19Trn7-0006NB-0f for guile-devel@m.gmane.org; Sat, 21 Jun 2003 19:29:05 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.20) id 19Trml-0006Gy-K7 for guile-devel@gnu.org; Sat, 21 Jun 2003 19:28:43 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.20) id 19Trmj-0006DT-7t for guile-devel@gnu.org; Sat, 21 Jun 2003 19:28:41 -0400 Original-Received: from snoopy.pacific.net.au ([61.8.0.36]) by monty-python.gnu.org with esmtp (Exim 4.20) id 19Trmi-000688-BN for guile-devel@gnu.org; Sat, 21 Jun 2003 19:28:40 -0400 Original-Received: from sunny.pacific.net.au (sunny.pacific.net.au [203.2.228.40]) h5LNSaYd022123 for ; Sun, 22 Jun 2003 09:28:36 +1000 Original-Received: from wisma.pacific.net.au (wisma.pacific.net.au [210.23.129.72]) by sunny.pacific.net.au with ESMTP id h5LNSaQg005389 for ; Sun, 22 Jun 2003 09:28:36 +1000 (EST) Original-Received: from localhost (ppp116.dyn228.pacific.net.au [203.143.228.116]) by wisma.pacific.net.au (8.12.9/8.12.9) with ESMTP id h5LNSYnh014578 for ; Sun, 22 Jun 2003 09:28:34 +1000 (EST) Original-Received: from gg by localhost with local (Exim 3.35 #1 (Debian)) id 19TrmV-0003pj-00; Sun, 22 Jun 2003 09:28:27 +1000 Original-To: guile-devel@gnu.org Mail-Copies-To: never In-Reply-To: <87n0gf0zbc.fsf@zagadka.ping.de> (Marius Vollmer's message of "19 Jun 2003 00:56:55 +0200") User-Agent: Gnus/5.090019 (Oort Gnus v0.19) Emacs/21.2 (gnu/linux) X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: Developers list for Guile, the GNU extensibility library List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.lisp.guile.devel:2569 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.devel:2569 Marius Vollmer 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" node. > 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 working). 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 iteration. (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)) ,@body) #t) (lambda (key arg) arg)))))) _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://mail.gnu.org/mailman/listinfo/guile-devel