r7rs-small-texinfo

Unnamed repository; edit this file 'description' to name the repository.
git clone https://kaka.farm/~git/r7rs-small-texinfo
Log | Files | Refs

commit ea7a15fba27ea3604d8c52e570bea78b976761c2
parent fdd6d84fc0e72c45c34527b2a6974e5220bd0a87
Author: Wolfgang Corcoran-Mathe <wcm@sigwinch.xyz>
Date:   Wed, 31 Jan 2024 23:51:14 -0500

Sequencing & Iteration: Texify.

Diffstat:
Mdoc/r7rs-small/r7rs-small.texinfo | 102++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------
1 file changed, 62 insertions(+), 40 deletions(-)

diff --git a/doc/r7rs-small/r7rs-small.texinfo b/doc/r7rs-small/r7rs-small.texinfo @@ -1979,66 +1979,86 @@ input and output. @print{} 4 plus 1 equals 5 @end example +@end deffn + Note that there is a third form of @code{begin} used as a library declaration. @xref{Library syntax} @node Iteration @subsection Iteration -syntax: (do ((@svar{variable1} @svar{init1} @svar{step1}) -@dots{}) -(@svar{test} @svar{expression} @dots{}) -@svar{command} @dots{}) - -Syntax: All of @svar{init}, @svar{step}, @svar{test}, and @svar{command} are expressions. - -Semantics: A do expression is an iteration construct. It specifies a set of variables to be -bound, how they are to be initialized at the start, and how they are to be updated on each -iteration. When a termination condition is met, the loop exits after evaluating the -@svar{expression}s. - -A do expression is evaluated as follows: The @svar{init} expressions are evaluated (in some -unspecified order), the @svar{variable}s are bound to fresh locations, the results of the @svar{init} -expressions are stored in the bindings of the @svar{variable}s, and then the iteration phase -begins. - -Each iteration begins by evaluating @svar{test}; if the result is false (see section 6.3), then the -@svar{command} expressions are evaluated in order for effect, the @svar{step} expressions are -evaluated in some unspecified order, the @svar{variable}s are bound to fresh locations, the -results of the @svar{step}s are stored in the bindings of the @svar{variable}s, and the next iteration -begins. +@c Since @deffn would put this whole complex form on one line in most +@c output types, I've put the actual syntax after definition header. +@c Maybe there's a better way? +@deffn syntax do -If @svar{test} evaluates to a true value, then the @svar{expression}s are evaluated from left to right -and the values of the last @svar{expression} are returned. If no @svar{expression}s are present, -then the value of the do expression is unspecified. +@format +@code{(do ((}@svar{variable@sub{1}} @svar{init@sub{1}} @svar{step@sub{1}}@code{)} + @dots{}@code{)} + @code{(}@svar{test} @svar{expression} @dots{}@code{)} + @svar{command} @dots{}@code{)} +@end format -The regionof the binding of a @svar{variable} consists of the entire do expression except for -the @svar{init}s. It is an error for a @svar{variable} to appear more than once in the list of do -variables. +Syntax: All of @svar{init}, @svar{step}, @svar{test}, and @svar{command} are expressions. -A @svar{step} can be omitted, in which case the effect is the same as if (@svar{variable} @svar{init} -@svar{variable}) had been written instead of (@svar{variable} @svar{init}). +Semantics: +A @code{do} expression is an iteration construct. It specifies a set of variables to +be bound, how they are to be initialized at the start, and how they are +to be updated on each iteration. When a termination condition is met, +the loop exits after evaluating the @svar{expression}s. + +A @code{do} expression is evaluated as follows: +The @svar{init} expressions are evaluated (in some unspecified order), +the @svar{variable}s are bound to fresh locations, the results of the +@svar{init} expressions are stored in the bindings of the +@svar{variable}s, and then the iteration phase begins. + +Each iteration begins by evaluating @svar{test}; if the result is +false (@xref{Booleans}), then the @svar{command} +expressions are evaluated in order for effect, the @svar{step} +expressions are evaluated in some unspecified order, the +@svar{variable}s are bound to fresh locations, the results of the +@svar{step}s are stored in the bindings of the +@svar{variable}s, and the next iteration begins. + +If @svar{test} evaluates to a true value, then the +@svar{expression}s are evaluated from left to right and the values of +the last @svar{expression} are returned. If no @svar{expression}s +are present, then the value of the @code{do} expression is unspecified. + +The region of the binding of a @svar{variable} +consists of the entire @code{do} expression except for the @svar{init}s. +It is an error for a @svar{variable} to appear more than once in the +list of @code{do} variables. + +A @svar{step} can be omitted, in which case the effect is the +same as if @code{(}@svar{variable} @svar{init} @svar{variable}@code{)} had +been written instead of @code{(}@svar{variable} @svar{init}@code{)}. @example (do ((vec (make-vector 5)) (i 0 (+ i 1))) ((= i 5) vec) - (vector-set! vec i i)) @result{} #(0 1 2 3 4) + (vector-set! vec i i)) @result{} #(0 1 2 3 4) (let ((x '(1 3 5 7 9))) (do ((x x (cdr x)) (sum 0 (+ sum (car x)))) - ((null? x) sum))) @result{} 25 + ((null? x) sum))) @result{} 25 @end example -syntax: (let @svar{variable} @svar{bindings} @svar{body}) +@end deffn -Semantics: ``Named let'' is a variant on the syntax of let which provides a more general -looping construct than do and can also be used to express recursion. It has the same -syntax and semantics as ordinary let except that @svar{variable} is bound within @svar{body} to a -procedure whose formal arguments are the bound variables and whose body is @svar{body}. -Thus the execution of @svar{body} can be repeated by invoking the procedure named by -@svar{variable}. +@deffn syntax let @svar{variable} @svar{bindings} @svar{body} + +``Named @code{let}'' is a variant on the syntax of @code{let} which provides +a more general looping construct than @code{do} and can also be used to express +recursion. +It has the same syntax and semantics as ordinary @code{let} +except that @svar{variable} is bound within @svar{body} to a procedure +whose formal arguments are the bound variables and whose body is +@svar{body}. Thus the execution of @svar{body} can be repeated by +invoking the procedure named by @svar{variable}. @example (let loop ((numbers '(3 -2 1 6 -5)) @@ -2053,9 +2073,11 @@ Thus the execution of @svar{body} can be repeated by invoking the procedure name (loop (cdr numbers) nonneg (cons (car numbers) neg))))) -@result{} ((6 1 3) (-5 -2)) + @result{} ((6 1 3) (-5 -2)) @end example +@end deffn + @node Delayed evaluation @subsection Delayed evaluation