/usr/share/doc/r5rs-doc/r5rs/Binding-constructs.html is in r5rs-doc 20010328-7.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | <html lang="en">
<head>
<title>Binding constructs - Revised(5) Scheme</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Revised(5) Scheme">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Derived-expression-types.html#Derived-expression-types" title="Derived expression types">
<link rel="prev" href="Conditional.html#Conditional" title="Conditional">
<link rel="next" href="Sequencing.html#Sequencing" title="Sequencing">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
pre.display { font-family:inherit }
pre.format { font-family:inherit }
pre.smalldisplay { font-family:inherit; font-size:smaller }
pre.smallformat { font-family:inherit; font-size:smaller }
pre.smallexample { font-size:smaller }
pre.smalllisp { font-size:smaller }
span.sc { font-variant:small-caps }
span.roman { font-family:serif; font-weight:normal; }
span.sansserif { font-family:sans-serif; font-weight:normal; }
--></style>
</head>
<body>
<div class="node">
<a name="Binding-constructs"></a>
<p>
Next: <a rel="next" accesskey="n" href="Sequencing.html#Sequencing">Sequencing</a>,
Previous: <a rel="previous" accesskey="p" href="Conditional.html#Conditional">Conditional</a>,
Up: <a rel="up" accesskey="u" href="Derived-expression-types.html#Derived-expression-types">Derived expression types</a>
<hr>
</div>
<h4 class="subsection">4.2.2 Binding constructs</h4>
<p><a name="index-g_t_0040w_007bbinding-constructs_007d-119"></a>
The three binding constructs ‘<samp><span class="samp">let</span></samp>’, ‘<samp><span class="samp">let*</span></samp>’, and ‘<samp><span class="samp">letrec</span></samp>’
give Scheme a block structure, like Algol 60. The syntax of the three
constructs is identical, but they differ in the regions they establish
<a name="index-g_t_0040w_007bregion_007d-120"></a>for their variable bindings. In a ‘<samp><span class="samp">let</span></samp>’ expression, the initial
values are computed before any of the variables become bound; in a
‘<samp><span class="samp">let*</span></samp>’ expression, the bindings and evaluations are performed
sequentially; while in a ‘<samp><span class="samp">letrec</span></samp>’ expression, all the bindings are in
effect while their initial values are being computed, thus allowing
mutually recursive definitions.
<div class="defun">
— library syntax: <b>let</b><var> <bindings> <body><a name="index-let-121"></a></var><br>
<blockquote>
<p><em>Syntax:</em>
<span class="roman"><Bindings></span> should have the form
<pre class="format"><tt>((</tt><span class="roman"><variable1></span> <span class="roman"><init1></span><tt>) <small class="dots">...</small>)</tt><span class="roman">,</span>
</pre>
<p>where each <span class="roman"><init></span> is an expression, and <span class="roman"><body></span> should be a
sequence of one or more expressions. It is
an error for a <span class="roman"><variable></span> to appear more than once in the list of variables
being bound.
<p><em>Semantics:</em>
The <span class="roman"><init></span>s are evaluated in the current environment (in some
unspecified order), the <span class="roman"><variable></span>s are bound to fresh locations
holding the results, the <span class="roman"><body></span> is evaluated in the extended
environment, and the value(s) of the last expression of <span class="roman"><body></span>
is(are) returned. Each binding of a <span class="roman"><variable></span> has <span class="roman"><body></span> as its
region.
<pre class="format"><tt>(let ((x 2) (y 3))
(* x y)) ==> 6
(let ((x 2) (y 3))
(let ((x 7)
(z (+ x y)))
(* z x))) ==> 35
</tt>
</pre>
<p>See also named ‘<samp><span class="samp">let</span></samp>’, section <a href="Iteration.html#Iteration">Iteration</a>.
</blockquote></div>
<div class="defun">
— library syntax: <b>let*</b><var> <bindings> <body><a name="index-let_002a-122"></a></var><br>
<blockquote>
<p><em>Syntax:</em>
<span class="roman"><Bindings></span> should have the form
<pre class="format"><tt>((</tt><span class="roman"><variable1></span> <span class="roman"><init1></span><tt>) <small class="dots">...</small>)</tt><span class="roman">,</span>
</pre>
<p>and <span class="roman"><body></span> should be a sequence of
one or more expressions.
<p><em>Semantics:</em>
‘<samp><span class="samp">Let*</span></samp>’ is similar to ‘<samp><span class="samp">let</span></samp>’, but the bindings are performed
sequentially from left to right, and the region of a binding indicated
by ‘<samp><span class="samp">(<variable> <init>)</span></samp>’ is that part of the ‘<samp><span class="samp">let*</span></samp>’
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.
<pre class="format"><tt>(let ((x 2) (y 3))
(let* ((x 7)
(z (+ x y)))
(* z x))) ==> 70
</tt>
</pre>
</blockquote></div>
<div class="defun">
— library syntax: <b>letrec</b><var> <bindings> <body><a name="index-letrec-123"></a></var><br>
<blockquote>
<p><em>Syntax:</em>
<span class="roman"><Bindings></span> should have the form
<pre class="format"><tt>((</tt><span class="roman"><variable1></span> <span class="roman"><init1></span><tt>) <small class="dots">...</small>)</tt><span class="roman">,</span>
</pre>
<p>and <span class="roman"><body></span> should be a sequence of
one or more expressions. It is an error for a <span class="roman"><variable></span> to appear more
than once in the list of variables being bound.
<p><em>Semantics:</em>
The <span class="roman"><variable></span>s are bound to fresh locations holding undefined
values, the <span class="roman"><init></span>s are evaluated in the resulting environment (in
some unspecified order), each <span class="roman"><variable></span> is assigned to the result
of the corresponding <span class="roman"><init></span>, the <span class="roman"><body></span> is evaluated in the
resulting environment, and the value(s) of the last expression in
<span class="roman"><body></span> is(are) returned. Each binding of a <span class="roman"><variable></span> has the
entire ‘<samp><span class="samp">letrec</span></samp>’ expression as its region, making it possible to
define mutually recursive procedures.
<pre class="format"><tt><!-- (letrec ((x 2) (y 3)) -->
<!-- (letrec ((foo (lambda (z) (+ x y z))) (x 7)) -->
<!-- (foo 4))) \ev 14 -->
(letrec ((even?
(lambda (n)
(if (zero? n)
#t
(odd? (- n 1)))))
(odd?
(lambda (n)
(if (zero? n)
#f
(even? (- n 1))))))
(even? 88))
==> #t
</tt>
</pre>
<p>One restriction on ‘<samp><span class="samp">letrec</span></samp>’ is very important: it must be possible
to evaluate each <span class="roman"><init></span> without assigning or referring to the value of any
<span class="roman"><variable></span>. If this restriction is violated, then it is an error. The
restriction is necessary because Scheme passes arguments by value rather than by
name. In the most common uses of ‘<samp><span class="samp">letrec</span></samp>’, all the <span class="roman"><init></span>s are
lambda expressions and the restriction is satisfied automatically.
<!-- \todo{use or uses? - Jinx.} -->
</blockquote></div>
</body></html>
|