From 3c9dcf6ce8e2f66d6c2d20d7f1f7187918c2f2dc Mon Sep 17 00:00:00 2001 From: Chris Hanson Date: Mon, 8 Nov 1999 18:23:39 +0000 Subject: [PATCH] Change order of arguments to VECTOR-MAP. --- v7/doc/ref-manual/scheme.texinfo | 10 +++++----- v7/src/runtime/vector.scm | 34 ++++++++++++++++++-------------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/v7/doc/ref-manual/scheme.texinfo b/v7/doc/ref-manual/scheme.texinfo index bc50098d9..a14e07480 100644 --- a/v7/doc/ref-manual/scheme.texinfo +++ b/v7/doc/ref-manual/scheme.texinfo @@ -2,7 +2,7 @@ @iftex @finalout @end iftex -@comment $Id: scheme.texinfo,v 1.80 1999/08/20 20:52:45 cph Exp $ +@comment $Id: scheme.texinfo,v 1.81 1999/11/08 18:23:39 cph Exp $ @comment %**start of header (This is for running Texinfo on a region.) @setfilename scheme.info @settitle MIT Scheme Reference @@ -7850,7 +7850,7 @@ initialized from the corresponding elements of @var{vector}. The remaining elements of the result are unspecified. @end deffn -@deffn {procedure+} vector-map vector procedure +@deffn {procedure+} vector-map procedure vector @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 @@ -7860,10 +7860,10 @@ elements of @var{vector} is unspecified. @example @group -(vector-map '#((a b) (d e) (g h)) cadr) @result{} #(b e h) -(vector-map '#(1 2 3 4) (lambda (n) (expt n n))) +(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 + '#(5 7 9)) @result{} #(5 7 9) @end group @end example @end deffn diff --git a/v7/src/runtime/vector.scm b/v7/src/runtime/vector.scm index 7ddcf8b6f..7bec8eea7 100644 --- a/v7/src/runtime/vector.scm +++ b/v7/src/runtime/vector.scm @@ -1,6 +1,6 @@ #| -*-Scheme-*- -$Id: vector.scm,v 14.12 1999/01/02 06:19:10 cph Exp $ +$Id: vector.scm,v 14.13 1999/11/08 18:22:52 cph Exp $ Copyright (c) 1988-1999 Massachusetts Institute of Technology @@ -110,20 +110,24 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. (loop (fix:+ index 1))))) vector)) -(define (vector-map vector procedure) - (guarantee-vector vector 'VECTOR-MAP) - (let ((length (vector-length vector))) - (if (fix:= 0 length) - vector - (let ((result (make-vector length))) - (let loop ((index 0)) - (if (fix:< index length) - (begin - (vector-set! result - index - (procedure (vector-ref vector index))) - (loop (fix:+ index 1))))) - result)))) +(define (vector-map procedure vector) + (if (and (vector? procedure) (procedure? vector)) + ;; KLUDGE: accept arguments in old order. + (vector-map vector procedure) + (begin + (guarantee-vector vector 'VECTOR-MAP) + (let ((length (vector-length vector))) + (if (fix:= 0 length) + vector + (let ((result (make-vector length))) + (let loop ((index 0)) + (if (fix:< index length) + (begin + (vector-set! result + index + (procedure (vector-ref vector index))) + (loop (fix:+ index 1))))) + result)))))) (define (for-each-vector-element vector procedure) (guarantee-vector vector 'FOR-EACH-VECTOR-ELEMENT) -- 2.25.1