/usr/share/doc/r5rs-doc/r5rs/Iteration.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 | <html lang="en">
<head>
<title>Iteration - 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="Sequencing.html#Sequencing" title="Sequencing">
<link rel="next" href="Delayed-evaluation.html#Delayed-evaluation" title="Delayed evaluation">
<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="Iteration"></a>
<p>
Next: <a rel="next" accesskey="n" href="Delayed-evaluation.html#Delayed-evaluation">Delayed evaluation</a>,
Previous: <a rel="previous" accesskey="p" href="Sequencing.html#Sequencing">Sequencing</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.4 Iteration</h4>
<!-- \unsection -->
<p><a name="index-g_t_0040w_007biteration_007d-126"></a>
<div class="defun">
— library syntax: <b>(</b><var>do </var>((<var><variable1> <init1> <step1></var>)<var><a name="index-g_t_0028-127"></a></var><br>
<blockquote>
<p><tt> <small class="dots">...</small>) (</tt><span class="roman"><test></span> <span class="roman"><expression></span><tt> <small class="dots">...</small>) </tt><span class="roman"><command></span><tt> <small class="dots">...</small>)</tt>
<a name="index-g_t_0040w_007bdo_007d-128"></a>
‘<samp><span class="samp">Do</span></samp>’ 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 <span class="roman"><expression></span>s.
<p>‘<samp><span class="samp">Do</span></samp>’ expressions are evaluated as follows:
The <span class="roman"><init></span> expressions are evaluated (in some unspecified order),
the <span class="roman"><variable></span>s are bound to fresh locations, the results of the
<span class="roman"><init></span> expressions are stored in the bindings of the
<span class="roman"><variable></span>s, and then the iteration phase begins.
<p>Each iteration begins by evaluating <span class="roman"><test></span>; if the result is
false (see section see <a href="Booleans.html#Booleans">Booleans</a>), then the <span class="roman"><command></span>
expressions are evaluated in order for effect, the <span class="roman"><step></span>
expressions are evaluated in some unspecified order, the
<span class="roman"><variable></span>s are bound to fresh locations, the results of the
<span class="roman"><step></span>s are stored in the bindings of the
<span class="roman"><variable></span>s, and the next iteration begins.
<p>If <span class="roman"><test></span> evaluates to a true value, then the
<span class="roman"><expression></span>s are evaluated from left to right and the value(s) of
the last <span class="roman"><expression></span> is(are) returned. If no <span class="roman"><expression></span>s
are present, then the value of the ‘<samp><span class="samp">do</span></samp>’ expression is unspecified.
<p>The region of the binding of a <span class="roman"><variable></span>
<a name="index-g_t_0040w_007bregion_007d-129"></a>consists of the entire ‘<samp><span class="samp">do</span></samp>’ expression except for the <span class="roman"><init></span>s.
It is an error for a <span class="roman"><variable></span> to appear more than once in the
list of ‘<samp><span class="samp">do</span></samp>’ variables.
<p>A <span class="roman"><step></span> may be omitted, in which case the effect is the
same as if ‘<samp><span class="samp">(<variable> <init> <variable>)</span></samp>’ had
been written instead of ‘<samp><span class="samp">(<variable> <init>)</span></samp>’.
<pre class="format"><tt>(do ((vec (make-vector 5))
(i 0 (+ i 1)))
((= i 5) vec)
(vector-set! vec i i)) ==> #(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))) ==> 25
</tt>
</pre>
<!-- \end{entry} -->
— library syntax: <b>let</b><var> <variable> <bindings> <body><a name="index-let-130"></a></var><br>
<blockquote>
<p>“Named ‘<samp><span class="samp">let</span></samp>’” is a variant on the syntax of <code>let</code> which provides
<a name="index-g_t_0040w_007blet_007d-131"></a>a more general looping construct than ‘<samp><span class="samp">do</span></samp>’ and may also be used to express
recursions.
It has the same syntax and semantics as ordinary ‘<samp><span class="samp">let</span></samp>’
except that <span class="roman"><variable></span> is bound within <span class="roman"><body></span> to a procedure
whose formal arguments are the bound variables and whose body is
<span class="roman"><body></span>. Thus the execution of <span class="roman"><body></span> may be repeated by
invoking the procedure named by <span class="roman"><variable></span>.
<!-- | <- right margin -->
<pre class="format"><tt>(let loop ((numbers '(3 -2 1 6 -5))
(nonneg '())
(neg '()))
(cond ((null? numbers) (list nonneg neg))
((>= (car numbers) 0)
(loop (cdr numbers)
(cons (car numbers) nonneg)
neg))
((< (car numbers) 0)
(loop (cdr numbers)
nonneg
(cons (car numbers) neg)))))
==> ((6 1 3) (-5 -2))
</tt>
</pre>
</blockquote></div>
</body></html>
|