@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
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
@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
#| -*-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
(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)