Next: , Previous: , Up: Data Structures   [Contents][Index]


7.1.3 Array Mapping

(require 'array-for-each)

Procedure: array-map! array0 proc array1 …

array1, … must have the same number of dimensions as array0 and have a range for each index which includes the range for the corresponding index in array0. proc is applied to each tuple of elements of array1 … and the result is stored as the corresponding element in array0. The value returned is unspecified. The order of application is unspecified.

Function: array-map prototype proc array1 array2 …

array2, … must have the same number of dimensions as array1 and have a range for each index which includes the range for the corresponding index in array1. proc is applied to each tuple of elements of array1, array2, … and the result is stored as the corresponding element in a new array of type prototype. The new array is returned. The order of application is unspecified.

Function: array-for-each proc array0 …

proc is applied to each tuple of elements of array0 … in row-major order. The value returned is unspecified.

Function: array-indexes array

Returns an array of lists of indexes for array such that, if li is a list of indexes for which array is defined, (equal? li (apply array-ref (array-indexes array) li)).

Function: array-index-for-each array proc

applies proc to the indices of each element of array in turn. The value returned and the order of application are unspecified.

One can implement array-index-map! as

(define (array-index-map! ra fun)
  (array-index-for-each
   ra
   (lambda is (apply array-set! ra (apply fun is) is))))
Procedure: array-index-map! array proc

applies proc to the indices of each element of array in turn, storing the result in the corresponding element. The value returned and the order of application are unspecified.

One can implement array-indexes as

(define (array-indexes array)
    (let ((ra (apply make-array '#() (array-dimensions array))))
      (array-index-map! ra (lambda x x))
      ra))

Another example:

(define (apl:index-generator n)
    (let ((v (make-vector n 1)))
      (array-index-map! v (lambda (i) i))
      v))
Procedure: array:copy! destination source

Copies every element from vector or array source to the corresponding element of destination. destination must have the same rank as source, and be at least as large in each dimension. The order of copying is unspecified.


Next: , Previous: , Up: Data Structures   [Contents][Index]