]> birchwood-abbey.net Git - mit-scheme.git/commitdiff
Update reference manual to match R7RS for {,vector-}{map,for-each}.
authorChris Hanson <org/chris-hanson/cph>
Tue, 16 Mar 2021 04:58:16 +0000 (21:58 -0700)
committerChris Hanson <org/chris-hanson/cph>
Thu, 18 Mar 2021 06:37:27 +0000 (23:37 -0700)
doc/ref-manual/lists.texi
doc/ref-manual/vectors.texi

index a266955244188623b2183a4ae3e4e6ad697b90f1..6c21a463260ba0193a13b71452085b53539346cb 100644 (file)
@@ -975,24 +975,31 @@ This could be used to define @code{memv} as follows:
 @cindex mapping, of list
 
 @deffn {standard procedure} map procedure list list @dots{}
-@var{Procedure} must be a procedure taking as many arguments as there
-are @var{list}s.  If more than one @var{list} is given, then they must
-all be the same length.  @code{map} applies @var{procedure} element-wise
-to the elements of the @var{list}s and returns a list of the results, in
-order from left to right.  The dynamic order in which @var{procedure} is
-applied to the elements of the @var{list}s is unspecified; use
-@code{for-each} to sequence side effects.
+It is an error if @var{procedure} does not accept as many arguments as
+there are @var{list}s and return a single value.
+
+The @code{map} procedure applies @var{procedure} element-wise to the
+elements of the @var{list}s and returns a list of the results, in
+order.  If more than one @var{list} is given and not all lists are the
+same length, @code{map} terminates when the shortest list runs out.
+The @var{list}s can be circular, but it is an error if all of them
+are circular.  It is an error for @var{procedure} to mutate any of the
+lists.  The dynamic order in which @var{procedure} is applied to the
+elements of the @var{list}s is unspecified.  If multiple returns occur
+from @code{map}, the values returned by earlier returns are not
+mutated.
 
 @example
 @group
-(map cadr '((a b) (d e) (g h)))           @result{} (b e h)
-(map (lambda (n) (expt n n)) '(1 2 3 4))  @result{} (1 4 27 256)
-(map + '(1 2 3) '(4 5 6))                 @result{} (5 7 9)
+(map cadr '((a b) (d e) (g h)))         @result{} (b e h)
+(map (lambda (n) (expt n n)) '(1 2 3 4 5))
+                                        @result{} (1 4 27 256 3125)
+(map + '(1 2 3) '(4 5 6 7))             @result{} (5 7 9)
 (let ((count 0))
   (map (lambda (ignored)
          (set! count (+ count 1))
          count)
-       '(a b c)))                         @result{} @r{unspecified}
+       '(a b)))                         @result{} (1 2) @r{or} (2 1)
 @end group
 @end example
 @end deffn
@@ -1085,12 +1092,20 @@ Deprecated, use @code{fold-right} instead.  Equivalent to
 
 
 @deffn {standard procedure} for-each procedure list list @dots{}
+It is an error if @var{procedure} does not accept as many arguments as
+there are @var{list}s.
+
 The arguments to @code{for-each} are like the arguments to @code{map},
 but @code{for-each} calls @var{procedure} for its side effects rather
 than for its values.  Unlike @code{map}, @code{for-each} is guaranteed
-to call @var{procedure} on the elements of the @var{list}s in order from
-the first element to the last, and the value returned by @code{for-each}
-is unspecified.
+to call @var{procedure} on the elements of the @var{list}s in order
+from the first element(s) to the last, and the value returned by
+@code{for-each} is unspecified.  If more than one @var{list} is given
+and not all lists have the same length, @code{for-each} terminates
+when the shortest @var{list} runs out.  The @var{list}s can be
+circular, but it is an error if all of them are circular.
+
+It is an error for @var{procedure} to mutate any of the lists.
 
 @example
 @group
index 943e8bc6d47be3f8350ae96c4ac83396ceb9beff..309657aefc5fac8f9c005b8bd4dba3b149ff81f4 100644 (file)
@@ -142,24 +142,52 @@ initialized from the corresponding elements of @var{vector}.  The
 remaining elements of the result are unspecified.
 @end deffn
 
-@deffn procedure vector-map procedure vector
+@deffn {standard procedure} vector-map procedure vector vector @dots{}
 @cindex mapping, of vector
-@var{Procedure} must be a procedure of one argument.  @code{vector-map}
-applies @var{procedure} element-wise to the elements of @var{vector} and
-returns a newly allocated vector of the results, in order from left to
-right.  The dynamic order in which @var{procedure} is applied to the
-elements of @var{vector} is unspecified.
+It is an error if @var{procedure} does not accept as many arguments as
+there are @var{vector}s and return a single value.
+
+The @code{vector-map} procedure applies @var{procedure} element-wise
+to the elements of the @var{vector}s and returns a vector of the
+results, in order.  If more than one @var{vector} is given and not all
+vectors are the same length, @code{vector-map} terminates when the
+shortest vector runs out.  The dynamic order in which @var{procedure}
+is applied to the elements of the @var{vector}s is unspecified.  If
+multiple returns occur from @code{vector-map}, the values returned by
+earlier returns are not mutated.
 
 @example
 @group
-(vector-map cadr '#((a b) (d e) (g h)))     @result{}  #(b e h)
-(vector-map (lambda (n) (expt n n)) '#(1 2 3 4))
-                                            @result{}  #(1 4 27 256)
-(vector-map + '#(5 7 9))                    @result{}  #(5 7 9)
+(vector-map cadr '#((a b) (d e) (g h))) @result{}  #(b e h)
+(vector-map (lambda (n) (expt n n)) '#(1 2 3 4 5))
+                                        @result{}  #(1 4 27 256 3125)
+(vector-map + '#(1 2 3) '#(4 5 6 7))    @result{}  #(5 7 9)
+(let ((count 0))
+  (vector-map (lambda (ignored)
+                (set! count (+ count 1))
+                count)
+              '#(a b)))                 @result{} #(1 2) @r{or} #(2 1)
 @end group
 @end example
 @end deffn
 
+@deffn {standard procedure} vector-for-each procedure vector vector @dots{}
+It is an error if @var{procedure} does not accept as many arguments as
+there are @var{vector}s.
+
+The arguments to @code{vector-for-each} are like the arguments to
+@code{vector-map}, but @code{vector-for-each} calls @var{procedure} for
+its side effects rather than for its values.  Unlike @code{vector-map},
+@code{vector-for-each} is guaranteed to call @var{procedure} on the
+elements of the @var{vector}s in order from the first element(s) to
+the last, and the value returned by @code{vector-for-each} is
+unspecified.  If more than one @var{vector} is given and not all
+vectors have the same length, @code{vector-for-each} terminates when
+the shortest @var{vector} runs out.  It is an error for
+@var{procedure} to mutate any of the vectors.
+@end deffn
+
+
 @node Selecting Vector Components, Cutting Vectors, Construction of Vectors, Vectors
 @section Selecting Vector Components
 @cindex selection, of vector component