commit ef78e027d1a629a8dfb33b72e9cc250cb5607ba9
parent c1e8c6658693bd2c460e483979d160d142811a9b
Author: Wolfgang Corcoran-Mathe <wcm@sigwinch.xyz>
Date: Wed, 31 Jan 2024 21:10:52 -0500
Binding constructs: Texify.
Diffstat:
1 file changed, 101 insertions(+), 59 deletions(-)
diff --git a/doc/r7rs-small/r7rs-small.texinfo b/doc/r7rs-small/r7rs-small.texinfo
@@ -1749,23 +1749,32 @@ a core set of features is given in appendix B.
@node Binding constructs
@subsection Binding constructs
-The binding constructs let, let*, letrec, letrec*, let-values, and let*-values give Scheme a
-block structure, like Algol 60. The syntax of the first four constructs is identical, but they
-differ in the regionsthey establish for their variable bindings. In a let expression, the
-initial values are computed before any of the variables become bound; in a let*
-expression, the bindings and evaluations are performed sequentially; while in letrec and
-letrec* expressions, all the bindings are in effect while their initial values are being
-computed, thus allowing mutually recursive definitions. The let-values and let*-values
-constructs are analogous to let and let* respectively, but are designed to handle
-multiple-valued expressions, binding different identifiers to the returned values.
-
-syntax: (let @svar{bindings} @svar{body})
+The binding constructs @code{let}, @code{let*}, @code{letrec}, @code{letrec*},
+@code{let-values}, and @code{let*-values}
+give Scheme a block structure, like Algol 60. The syntax of the first four
+constructs is identical, but they differ in the regions they establish
+for their variable bindings. In a @code{let} expression, the initial
+values are computed before any of the variables become bound; in a
+@code{let*} expression, the bindings and evaluations are performed
+sequentially; while in @code{letrec} and @code{letrec*} expressions,
+all the bindings are in
+effect while their initial values are being computed, thus allowing
+mutually recursive definitions.
+The @code{let-values} and @code{let*-values} constructs are analogous to @code{let} and @code{let*}
+respectively, but are designed to handle multiple-valued expressions, binding
+different identifiers to the returned values.
+
+@deffn syntax let @svar{bindings} @svar{body}
Syntax: @svar{Bindings} has the form
-((@svar{variable1} @svar{init1}) @dots{}),where each @svar{init} is an expression, and @svar{body} is a sequence of
+@display
+@code{((}@svar{variable@sub{1}} @svar{init@sub{1}}@code{)} @dots{}@code{)},
+@end display
+
+where each @svar{init} is an expression, and @svar{body} is a sequence of
zero or more definitions followed by a sequence of one or more expressions as described
-in section 4.1.4. It is an error for a @svar{variable} to appear more than once in the list of
+in @ref{Expressions}. It is an error for a @svar{variable} to appear more than once in the list of
variables being bound.
Semantics: The @svar{init}s are evaluated in the current environment (in some unspecified
@@ -1776,45 +1785,57 @@ are returned. Each binding of a @svar{variable} has @svar{body} as its region.
@example
(let ((x 2) (y 3))
- (* x y)) @result{} 6
+ (* x y)) @result{} 6
(let ((x 2) (y 3))
(let ((x 7)
(z (+ x y)))
- (* z x)))
- @result{}
- 35 See also ``named let,'' section 4.2.4.
+ (* z x))) @result{} 35
@end example
-syntax: (let* @svar{bindings} @svar{body})
+See also ``named @code{let},'' @ref{Iteration}.
+@end deffn
+
+@deffn syntax let* @svar{bindings} @svar{body}
Syntax: @svar{Bindings} has the form
-((@svar{variable1} @svar{init1}) @dots{}),and @svar{body} is a sequence of zero or more definitions followed by
-one or more expressions as described in section 4.1.4.
+@display
+@code{((}@svar{variable1} @svar{init@sub{1}}) @dots{}@code{)},
+@end display
+
+and @svar{body} is a sequence of zero or more definitions followed by
+one or more expressions as described in @ref{Expressions}.
-Semantics: The let* binding construct is similar to let, but the bindings are performed
-sequentially from left to right, and the regionof a binding indicated by (@svar{variable} @svar{init})
-is that part of the let* expression to the right of the binding. Thus the second binding is
-done in an environment in which the first binding is visible, and so on. The @svar{variable}s
-need not be distinct.
+Semantics:
+The @code{let*} binding construct is similar to @code{let}, but the bindings are performed
+sequentially from left to right, and the region of a binding indicated
+by @code{(}@svar{variable} @svar{init}@code{)} is that part of the @code{let*}
+expression to the right of the binding. Thus the second binding is done
+in an environment in which the first binding is visible, and so on.
+The @svar{variable}s need not be distinct.
@example
(let ((x 2) (y 3))
(let* ((x 7)
(z (+ x y)))
- (* z x))) @result{} 70
+ (* z x))) @result{} 70
@end example
+@end deffn
-syntax: (letrec @svar{bindings} @svar{body})
+@deffn syntax letrec @svar{bindings} @svar{body}
Syntax: @svar{Bindings} has the form
-((@svar{variable1} @svar{init1}) @dots{}),and @svar{body} is a sequence of zero or more definitions followed by
-one or more expressions as described in section 4.1.4. It is an error for a @svar{variable} to
+@display
+@code{((}@svar{variable@sub{1}} @svar{init@sub{1}}@code{)} @dots{}@code{)},
+@end display
+
+and @svar{body} is a sequence of zero or more definitions followed by
+one or more expressions as described in @ref{Expressions}. It is an error for a @svar{variable} to
appear more than once in the list of variables being bound.
Semantics: The @svar{variable}s are bound to fresh locations holding unspecified values, the
@@ -1837,29 +1858,34 @@ possible to define mutually recursive procedures.
#f
(even? (- n 1))))))
(even? 88))
-@result{} #t
+@result{} #t
@end example
-One restriction on letrec is very important: if it is not possible to evaluate each @svar{init}
+One restriction on @code{letrec} is very important: if it is not possible to evaluate each @svar{init}
without assigning or referring to the value of any @svar{variable}, it is an error. The restriction
-is necessary because letrec is defined in terms of a procedure call where a lambda
+is necessary because @code{letrec} is defined in terms of a procedure call where a @code{lambda}
expression binds the @svar{variable}s to the values of the @svar{init}s. In the most common uses of
-letrec, all the @svar{init}s are lambda expressions and the restriction is satisfied automatically.
+@code{letrec}, all the @svar{init}s are @code{lambda} expressions and the restriction is satisfied automatically.
+@end deffn
-syntax: (letrec* @svar{bindings} @svar{body})
+@deffn syntax letrec* @svar{bindings} @svar{body}
Syntax: @svar{Bindings} has the form
-((@svar{variable1} @svar{init1}) @dots{}),and @svar{body}is a sequence of zero or more definitions followed by
-one or more expressions as described in section 4.1.4. It is an error for a @svar{variable} to
+@display
+@code{((}@svar{variable@sub{1}} @svar{init@sub{1}}@code{)} @dots{}@code{)},
+@end display
+
+and @svar{body}is a sequence of zero or more definitions followed by
+one or more expressions as described in @ref{Expressions}. It is an error for a @svar{variable} to
appear more than once in the list of variables being bound.
Semantics: The @svar{variable}s are bound to fresh locations, each @svar{variable} is assigned in
left-to-right order to the result of evaluating the corresponding @svar{init} (interleaving
evaluations and assignments), the @svar{body} is evaluated in the resulting environment, and
the values of the last expression in @svar{body} are returned. Despite the left-to-right
-evaluation and assignment order, each binding of a @svar{variable} has the entire letrec*
+evaluation and assignment order, each binding of a @svar{variable} has the entire @code{letrec*}
expression as its region, making it possible to define mutually recursive procedures.
If it is not possible to evaluate each @svar{init} without assigning or referring to the value of
@@ -1891,24 +1917,33 @@ continuation of an @svar{init} more than once.
@end example
-Evaluating (means '(3 (1 4))) returns three values: 8/3, 2.28942848510666 (approximately),
+Evaluating @code{(means '(3 (1 4)))} returns three values: 8/3, 2.28942848510666 (approximately),
and 36/19.
+@end deffn
-syntax: (let-values @svar{mv binding spec} @svar{body})
+@deffn syntax let-values @svar{mv binding spec} @svar{body}
Syntax: @svar{Mv binding spec} has the form
-((@svar{formals1} @svar{init1}) @dots{}), where each @svar{init} is an expression, and @svar{body} is zero or more
-definitions followed by a sequence of one or more expressions as described in section
-4.1.4. It is an error for a variable to appear more than once in the set of @svar{formals}.
+@display
+@code{((}@svar{formals@sub{1}} @svar{init@sub{1}}@code{)} @dots{}@code{)},
+@end display
-Semantics: The @svar{init}s are evaluated in the current environment (in some unspecified
-order) as if by invoking call-with-values, and the variables occurring in the @svar{formals} are
-bound to fresh locations holding the values returned by the @svar{init}s, where the @svar{formals}
-are matched to the return values in the same way that the @svar{formals} in a lambda
-expression are matched to the arguments in a procedure call. Then, the @svar{body} is
-evaluated in the extended environment, and the values of the last expression of @svar{body}
-are returned. Each binding of a @svar{variable} has @svar{body} as its region.
+where each @svar{init} is an expression, and @svar{body} is zero or more
+definitions followed by a sequence of one or more expressions as described in @ref{Expressions}.
+It is an error for a variable to appear more than once in the set of @svar{formals}.
+
+Semantics:
+The @svar{init}s are evaluated in the current environment (in some
+unspecified order) as if by invoking @code{call-with-values}, and the
+variables occurring in the @svar{formals} are bound to fresh locations
+holding the values returned by the @svar{init}s, where the
+@svar{formals} are matched to the return values in the same way that
+the @svar{formals} in a @code{lambda} expression are matched to the
+arguments in a procedure call. Then, the @svar{body} is evaluated in
+the extended environment, and the values of the last expression of
+@svar{body} are returned. Each binding of a @svar{variable} has
+@svar{body} as its region.
It is an error if the @svar{formals} do not match the number of values returned by the
corresponding @svar{init}.
@@ -1916,32 +1951,39 @@ corresponding @svar{init}.
@example
(let-values (((root rem) (exact-integer-sqrt 32)))
- (* root rem)) @result{} 35
+ (* root rem)) @result{} 35
@end example
+@end deffn
-syntax: (let*-values @svar{mv binding spec} @svar{body})
+@deffn syntax let*-values @svar{mv binding spec} @svar{body}
Syntax: @svar{Mv binding spec} has the form
-((@svar{formals} @svar{init}) @dots{}),and @svar{body} is a sequence of zero or more definitions followed by
-one or more expressions as described in section 4.1.4. In each @svar{formals}, it is an error if
+@display
+@code{((}@svar{formals} @svar{init}@code{)} @dots{}@code{)},
+@end display
+
+and @svar{body} is a sequence of zero or more definitions followed by
+one or more expressions as described in @ref{Expressions}. In each @svar{formals}, it is an error if
any variable appears more than once.
-Semantics: The let*-values construct is similar to let-values, but the @svar{init}s are evaluated
-and bindings created sequentially from left to right, with the region of the bindings of
-each @svar{formals} including the @svar{init}s to its right as well as @svar{body}. Thus the second @svar{init}
-is evaluated in an environment in which the first set of bindings is visible and initialized,
-and so on.
+The @code{let*-values} construct is similar to @code{let-values}, but the
+@svar{init}s are evaluated and bindings created sequentially from
+left to right, with the region of the bindings of each @svar{formals}
+including the @svar{init}s to its right as well as @svar{body}. Thus the
+second @svar{init} is evaluated in an environment in which the first
+set of bindings is visible and initialized, and so on.
@example
(let ((a 'a) (b 'b) (x 'x) (y 'y))
(let*-values (((a b) (values x y))
((x y) (values a b)))
- (list a b x y))) @result{} (x y x y)
+ (list a b x y))) @result{} (x y x y)
@end example
+@end deffn
@node Sequencing
@subsection Sequencing