- make-array interval getter #!optional setterprocedure
Assume first that the optional argument setter is not given.
If interval is an interval and getter is a function from interval to Scheme objects, then make-array returns an array with domain interval and getter getter.
It is an error to call make-array if interval and getter do not satisfy these conditions.
If now setter is specified, assume that it is a procedure such that getter and setter satisfy: If
(i1,...,in) $\neq$ (j1,...,jn)
are elements of interval and
(getter j1 ... jn) => x
then "after"
(setter v i1 ... in)
we have
(getter j1 ... jn) => x
and
(getter i1,...,in) => v
Then make-array builds a mutable array with domain interval, getter getter, and setter setter. It is an error to call make-array if its arguments do not satisfy these conditions.
Example:
(define a (make-array (make-interval '#(1 1) '#(11 11)) (lambda (i j) (if (= i j) 1 0))))
defines an array for which (array-getter a) returns 1 when i=j and 0 otherwise.
Example:
(define a ;; a sparse array (let ((domain (make-interval '#(1000000 1000000))) (sparse-rows (make-vector 1000000 '()))) (make-array domain (lambda (i j) (cond ((assv j (vector-ref sparse-rows i)) => cdr) (else 0.0))) (lambda (v i j) (cond ((assv j (vector-ref sparse-rows i)) => (lambda (pair) (set-cdr! pair v))) (else (vector-set! sparse-rows i (cons (cons j v) (vector-ref sparse-rows i))))))))) (define a_ (array-getter a)) (define a! (array-setter a)) (a_ 12345 6789) => 0. (a_ 0 0) => 0. (a! 1.0 0 0) => undefined (a_ 12345 6789) => 0. (a_ 0 0) => 1.