From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Kevin Ryde Newsgroups: gmane.lisp.guile.bugs Subject: Re: minor proposed changed to guile doc Date: Thu, 02 Sep 2004 07:29:24 +1000 Sender: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Message-ID: <87n009n0ej.fsf@zip.com.au> References: <20040901154937.84224.qmail@web10904.mail.yahoo.com> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1094074237 14649 80.91.224.253 (1 Sep 2004 21:30:37 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 1 Sep 2004 21:30:37 +0000 (UTC) Cc: bug-guile@gnu.org Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Wed Sep 01 23:30:18 2004 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1C2cgL-0007Vr-00 for ; Wed, 01 Sep 2004 23:30:18 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1C2clI-0008MG-1x for guile-bugs@m.gmane.org; Wed, 01 Sep 2004 17:35:24 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1C2clD-0008Jb-Nq for bug-guile@gnu.org; Wed, 01 Sep 2004 17:35:19 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1C2clC-0008Ir-AS for bug-guile@gnu.org; Wed, 01 Sep 2004 17:35:18 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1C2clC-0008IP-8u for bug-guile@gnu.org; Wed, 01 Sep 2004 17:35:18 -0400 Original-Received: from [61.8.0.85] (helo=mailout2.pacific.net.au) by monty-python.gnu.org with esmtp (Exim 4.34) id 1C2cg0-0003ur-Qu for bug-guile@gnu.org; Wed, 01 Sep 2004 17:29:57 -0400 Original-Received: from mailproxy2.pacific.net.au (mailproxy2.pacific.net.au [61.8.0.87]) by mailout2.pacific.net.au (8.12.3/8.12.3/Debian-6.6) with ESMTP id i81LTsje018076; Thu, 2 Sep 2004 07:29:54 +1000 Original-Received: from localhost (ppp2B3A.dyn.pacific.net.au [61.8.43.58]) by mailproxy2.pacific.net.au (8.12.3/8.12.3/Debian-6.6) with ESMTP id i81LTq78007275; Thu, 2 Sep 2004 07:29:52 +1000 Original-Received: from gg by localhost with local (Exim 3.36 #1 (Debian)) id 1C2cfW-0000hI-00; Thu, 02 Sep 2004 07:29:26 +1000 Original-To: first last In-Reply-To: <20040901154937.84224.qmail@web10904.mail.yahoo.com> (first last's message of "Wed, 1 Sep 2004 08:49:37 -0700 (PDT)") User-Agent: Gnus/5.110003 (No Gnus v0.3) Emacs/21.3 (gnu/linux) X-BeenThere: bug-guile@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.lisp.guile.bugs:1639 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.bugs:1639 first last writes: > > I propose that the following section replace the > current documentation for the DO function. It > essentially replaces "test" with "terminate" and > "expr" with "result". I revised `do' per below in the cvs head, perhaps it's clearer. -- syntax: do ((variable init [step]) ...) (test [expr ...]) body ... Bind VARIABLEs and evaluate BODY until TEST is true. The return value is the last EXPR after TEST, if given. A simple example will illustrate the basic form, (do ((i 1 (1+ i))) ((> i 4)) (display i)) -| 1234 Or with two variables and a final return value, (do ((i 1 (1+ i)) (p 3 (* 3 p))) ((> i 4) p) (format #t "3**~s is ~s\n" i p)) -| 3**1 is 3 3**2 is 9 3**3 is 27 3**4 is 81 => 789 The VARIABLE bindings are established like a `let', in that the expressions are all evaluated and then all bindings made. When iterating, the optional STEP expressions are evaluated with the previous bindings in scope, then new bindings all made. The TEST expression is a termination condition. Looping stops when the TEST is true. It's evaluated before running the BODY each time, so if it's true the first time then BODY is not run at all. The optional EXPRs after the TEST are evaluated at the end of looping, with the final VARIABLE bindings available. The last EXPR gives the return value, or if there are no EXPRs the return value is unspecified. Each iteration establishes bindings to fresh locations for the VARIABLEs, like a new `let' for each iteration. This is done for VARIABLEs without STEP expressions too. The following illustrates this, showing how a new `i' is captured by the `lambda' in each iteration (*note The Concept of Closure: About Closure.). (define lst '()) (do ((i 1 (1+ i))) ((> i 4)) (set! lst (cons (lambda () i) lst))) (map (lambda (proc) (proc)) lst) => (4 3 2 1) _______________________________________________ Bug-guile mailing list Bug-guile@gnu.org http://lists.gnu.org/mailman/listinfo/bug-guile