For more information including compatibility, examples and test cases, see https://github.com/petercrlane/r7rs-libs

0.1. Array Mapping: (import (slib array-for-each))

This library provides implementations of for-each and map for matrices, as well as functions to work on the indices of a matrix.

0.1.1. array-for-each

array-for-each takes a procedure and one or more matrices. The procedure is applied to the equivalent elements of each matrix in row-major 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]> (array-for-each display x)
1234#t

0.1.2. array-indexes

array-indexes 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]> (array-indexes x)
#<<array> 0x2b52960>
sash[r7rs]> (matrix->lists (array-indexes x))
(((0 0) (0 1)) ((1 0) (1 1)))

0.1.3. array-index-for-each

array-index-for-each 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]> (array-index-for-each x (lambda args (map display args)))
11011000#t

Notice the order of application is not specified.

0.1.4. array-index-map!

array-index-map! 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]> (array-index-map! 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. array-map!

array-map! 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 row-major 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]> (array-map! x + x y)
#t
sash[r7rs]> (matrix->lists x)                             ; <1>
((6 8) (10 12))
  1. matrix→lists is from (slib determinant)

0.1.6. array-map

array-map takes a matrix prototype, a procedure and one or more matrices. The procedure is applied to the equivalent elements of each matrix in row-major 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 (array-map #() + x y))           ; <1>
((6 8) (10 12))
  1. 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)