For more information including compatibility, examples and test cases, see https://github.com/petercrlane/r7rslibs
0.1. Array Mapping: (import (slib arrayforeach))
This library provides implementations of foreach
and map
for matrices, as well as functions
to work on the indices of a matrix.
0.1.1. arrayforeach
arrayforeach
takes a procedure and one or more matrices. The procedure
is applied to the equivalent elements of each matrix in rowmajor order.
The example below simply displays each element in the given array and returns #t
.
sash[r7rs]> (define x (list>array 2 #() '((1 2) (3 4)))) #<unspecified> sash[r7rs]> (arrayforeach display x) 1234#t
0.1.2. arrayindexes
arrayindexes
takes a matrix as an argument and returns a new matrix
of the same dimensions with lists of indexes in each element position.
sash[r7rs]> (define x (list>array 2 #() '((1 2) (3 4)))) #<unspecified> sash[r7rs]> (arrayindexes x) #<<array> 0x2b52960> sash[r7rs]> (matrix>lists (arrayindexes x)) (((0 0) (0 1)) ((1 0) (1 1)))
0.1.3. arrayindexforeach
arrayindexforeach
takes a matrix and a procedure and applies
the procedure to the indices of each element in the matrix.
sash[r7rs]> (define x (list>array 2 #() '((1 2) (3 4)))) #<unspecified> sash[r7rs]> (arrayindexforeach x (lambda args (map display args))) 11011000#t
Notice the order of application is not specified.
0.1.4. arrayindexmap!
arrayindexmap!
takes a matrix and a procedure and applies
the procedure to the indices of each element in the matrix storing the return
value in the corresponding element of the matrix.
sash[r7rs]> (define a (vector 0 0 0)) #<unspecified> sash[r7rs]> a #(0 0 0) sash[r7rs]> (arrayindexmap! a (lambda args (apply + args))) #t sash[r7rs]> a #(0 1 2)
In this case, the original matrix a
has the sum of its indices placed into its elements.
0.1.5. arraymap!
arraymap!
takes a result matrix, a procedure and one or more source matrices.
The procedure is applied to the equivalent elements of each suorce matrix in rowmajor order.
The return values of the procedure are placed into the respective element of the result matrix.
In the example below x
is used as both the result matrix and the first source matrix.
sash[r7rs]> (define x (list>array 2 #() '((1 2) (3 4)))) #<unspecified> sash[r7rs]> (define y (list>array 2 #() '((5 6) (7 8)))) #<unspecified> sash[r7rs]> (arraymap! x + x y) #t sash[r7rs]> (matrix>lists x) ; <1> ((6 8) (10 12))

matrix→lists
is from(slib determinant)
0.1.6. arraymap
arraymap
takes a matrix prototype, a procedure and one or more matrices.
The procedure is applied to the equivalent elements of each matrix in rowmajor order.
The return values of the procedure are placed into the respective element of a new matrix
built using the type of the given prototype.
sash[r7rs]> (define x (list>array 2 #() '((1 2) (3 4)))) #<unspecified> sash[r7rs]> (define y (list>array 2 #() '((5 6) (7 8)))) #<unspecified> sash[r7rs]> (matrix>lists (arraymap #() + x y)) ; <1> ((6 8) (10 12))

matrix→lists
is from(slib determinant)
0.1.7. array:copy!
array:copy!
copies the elements of the second vector or matrix into the
corresponding positions of the first vector or matrix; the destination must be at least
as large as the source in each dimension.
sash[r7rs]> (define v (vector 1 2 3)) #<unspecified> sash[r7rs]> (define w (vector 4 5 6)) #<unspecified> sash[r7rs]> v #(1 2 3) sash[r7rs]> (array:copy! v w) #t sash[r7rs]> v #(4 5 6)