This file is indexed.

/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:&nbsp;<a rel="next" accesskey="n" href="Delayed-evaluation.html#Delayed-evaluation">Delayed evaluation</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="Sequencing.html#Sequencing">Sequencing</a>,
Up:&nbsp;<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">
&mdash; library syntax: <b>(</b><var>do </var>((<var>&lt;variable1&gt; &lt;init1&gt; &lt;step1&gt;</var>)<var><a name="index-g_t_0028-127"></a></var><br>
<blockquote>
     <p><tt> <small class="dots">...</small>) (</tt><span class="roman">&lt;test&gt;</span> <span class="roman">&lt;expression&gt;</span><tt> <small class="dots">...</small>) </tt><span class="roman">&lt;command&gt;</span><tt> <small class="dots">...</small>)</tt>
<a name="index-g_t_0040w_007bdo_007d-128"></a>
&lsquo;<samp><span class="samp">Do</span></samp>&rsquo; 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">&lt;expression&gt;</span>s.

     <p>&lsquo;<samp><span class="samp">Do</span></samp>&rsquo; expressions are evaluated as follows:
The <span class="roman">&lt;init&gt;</span> expressions are evaluated (in some unspecified order),
the <span class="roman">&lt;variable&gt;</span>s are bound to fresh locations, the results of the
<span class="roman">&lt;init&gt;</span> expressions are stored in the bindings of the
<span class="roman">&lt;variable&gt;</span>s, and then the iteration phase begins.

     <p>Each iteration begins by evaluating <span class="roman">&lt;test&gt;</span>; if the result is
false (see section see <a href="Booleans.html#Booleans">Booleans</a>), then the <span class="roman">&lt;command&gt;</span>
expressions are evaluated in order for effect, the <span class="roman">&lt;step&gt;</span>
expressions are evaluated in some unspecified order, the
<span class="roman">&lt;variable&gt;</span>s are bound to fresh locations, the results of the
<span class="roman">&lt;step&gt;</span>s are stored in the bindings of the
<span class="roman">&lt;variable&gt;</span>s, and the next iteration begins.

     <p>If <span class="roman">&lt;test&gt;</span> evaluates to a true value, then the
<span class="roman">&lt;expression&gt;</span>s are evaluated from left to right and the value(s) of
the last <span class="roman">&lt;expression&gt;</span> is(are) returned.  If no <span class="roman">&lt;expression&gt;</span>s
are present, then the value of the &lsquo;<samp><span class="samp">do</span></samp>&rsquo; expression is unspecified.

     <p>The region of the binding of a <span class="roman">&lt;variable&gt;</span>
<a name="index-g_t_0040w_007bregion_007d-129"></a>consists of the entire &lsquo;<samp><span class="samp">do</span></samp>&rsquo; expression except for the <span class="roman">&lt;init&gt;</span>s. 
It is an error for a <span class="roman">&lt;variable&gt;</span> to appear more than once in the
list of &lsquo;<samp><span class="samp">do</span></samp>&rsquo; variables.

     <p>A <span class="roman">&lt;step&gt;</span> may be omitted, in which case the effect is the
same as if &lsquo;<samp><span class="samp">(&lt;variable&gt; &lt;init&gt; &lt;variable&gt;)</span></samp>&rsquo; had
been written instead of &lsquo;<samp><span class="samp">(&lt;variable&gt; &lt;init&gt;)</span></samp>&rsquo;.

     <pre class="format"><tt>(do ((vec (make-vector 5))
          (i 0 (+ i 1)))
         ((= i 5) vec)
       (vector-set! vec i i))               ==&gt;  #(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)))                ==&gt;  25
     </tt>
</pre>
     <!-- \end{entry} -->
&mdash; library syntax: <b>let</b><var> &lt;variable&gt; &lt;bindings&gt; &lt;body&gt;<a name="index-let-130"></a></var><br>
<blockquote>
     <p>&ldquo;Named &lsquo;<samp><span class="samp">let</span></samp>&rsquo;&rdquo; 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 &lsquo;<samp><span class="samp">do</span></samp>&rsquo; and may also be used to express
recursions. 
It has the same syntax and semantics as ordinary &lsquo;<samp><span class="samp">let</span></samp>&rsquo;
except that <span class="roman">&lt;variable&gt;</span> is bound within <span class="roman">&lt;body&gt;</span> to a procedure
whose formal arguments are the bound variables and whose body is
<span class="roman">&lt;body&gt;</span>.  Thus the execution of <span class="roman">&lt;body&gt;</span> may be repeated by
invoking the procedure named by <span class="roman">&lt;variable&gt;</span>.

     <!-- |  <- right margin -->
     <pre class="format"><tt>(let loop ((numbers '(3 -2 1 6 -5))
                (nonneg '())
                (neg '()))
       (cond ((null? numbers) (list nonneg neg))
             ((&gt;= (car numbers) 0)
              (loop (cdr numbers)
                    (cons (car numbers) nonneg)
                    neg))
             ((&lt; (car numbers) 0)
              (loop (cdr numbers)
                    nonneg
                    (cons (car numbers) neg)))))
               ==&gt;  ((6 1 3) (-5 -2))
     </tt>
</pre>
     </blockquote></div>

</body></html>