* minor proposed changed to guile doc
@ 2004-09-01 15:49 first last
2004-09-01 21:29 ` Kevin Ryde
0 siblings, 1 reply; 2+ messages in thread
From: first last @ 2004-09-01 15:49 UTC (permalink / raw)
I propose that the following section replace the
current documentation for the DO function. It
essentially replaces "test" with "terminate" and
"expr" with "result".
The motiviation is to make it more obvious that the
loop ends on a true value for the test. (as opposed
to "continue on true").
If I should make the change to a CVS working version
directly, please let me know (directly to me as I
don't check this list regularly). Otherwise I will
assume/hope someone else makes the change if its
acceptable.
-sp-
------------
- syntax: do ((variable1 init1 step1) ...) (terminate
result1 ...) command ...
The INIT expressions are evaluated and the
VARIABLES are bound to
their values. Then looping starts with testing
the TERMINATE
expression. If TERMINATE evaluates to a true
value, the RESULT following
the TERMINATE are evaluated and the value of the
last RESULT is returned
as the value of the `do' expression. If
TERMINATE evaluates to false,
the COMMANDs are evaluated in order, the STEPs
are evaluated and
stored into the VARIABLES and the next iteration
starts.
Any of the STEP expressions may be omitted, so
that the
corresponding variable is not changed during
looping.
_______________________________
Do you Yahoo!?
Win 1 of 4,000 free domain names from Yahoo! Enter now.
http://promotions.yahoo.com/goldrush
_______________________________________________
Bug-guile mailing list
Bug-guile@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-guile
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: minor proposed changed to guile doc
2004-09-01 15:49 minor proposed changed to guile doc first last
@ 2004-09-01 21:29 ` Kevin Ryde
0 siblings, 0 replies; 2+ messages in thread
From: Kevin Ryde @ 2004-09-01 21:29 UTC (permalink / raw)
Cc: bug-guile
first last <oic2day@yahoo.com> 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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2004-09-01 21:29 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-09-01 15:49 minor proposed changed to guile doc first last
2004-09-01 21:29 ` Kevin Ryde
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).