File: vector-map

package info (click to toggle)
scheme9 2025.08.12-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,080 kB
  • sloc: lisp: 16,752; ansic: 11,869; sh: 806; makefile: 237; sed: 6
file content (21 lines) | stat: -rw-r--r-- 736 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
S9 LIB  (vector-map procedure vector ...)   ==>  vector
        (vector-map! procedure vector ...)  ==>  unspecific

        (load-from-library "vector-map.scm")

Map a procedure over a set of vectors, giving a new vector

      (vector (f (vector-ref v0 i) ... ) ...)

where F is the given PROCEDURE, V0 is the first and VN is the last
VECTOR specified. The arity of PROCEDURE must match the number of
vectors passed to these procedures. VECTOR-MAP is to vectors what
MAP is to lists.

VECTOR-MAP! does not create a fresh vector, but changes the members
of the *first* vector in situ.

(vector-map + '#(1 2 3) '#(4 5 6))  ==>  #(5 7 9)
(let ((v (vector 1 2 3)))
  (vector-map! - v)
  v)                                ==>  #(-1 -2 -3)