Next: Shared Arrays, Previous: Array Syntax, Up: Arrays
When an array is created, the range of each dimension must be specified, e.g., to create a 2x3 array with a zero-based index:
(make-array 'ho 2 3) => #2((ho ho ho) (ho ho ho))
The range of each dimension can also be given explicitly, e.g., another way to create the same array:
(make-array 'ho '(0 1) '(0 2)) => #2((ho ho ho) (ho ho ho))
The following procedures can be used with arrays (or vectors). An argument shown as idx... means one parameter for each dimension in the array. A idxlist argument means a list of such values, one for each dimension.
Return
#t
if the obj is an array, and#f
if not.The second argument to scm_array_p is there for historical reasons, but it is not used. You should always pass
SCM_UNDEFINED
as its value.
Return
#t
if the obj is an array of type type, and#f
if not.
Return
0
if the obj is an array of type type, and1
if not.
Equivalent to
(make-typed-array #t
fill bound...)
.
Create and return an array that has as many dimensions as there are bounds and (maybe) fill it with fill.
The underlaying storage vector is created according to type, which must be a symbol whose name is the `vectag' of the array as explained above, or
#t
for ordinary, non-specialized arrays.For example, using the symbol
f64
for type will create an array that uses af64vector
for storing its elements, anda
will use a string.When fill is not the special unspecified value, the new array is filled with fill. Otherwise, the initial contents of the array is unspecified. The special unspecified value is stored in the variable
*unspecified*
so that for example(make-typed-array 'u32 *unspecified* 4)
creates a uninitializedu32
vector of length 4.Each bound may be a positive non-zero integer N, in which case the index for that dimension can range from 0 through N-1; or an explicit index range specifier in the form
(LOWER UPPER)
, where both lower and upper are integers, possibly less than zero, and possibly the same number (however, lower cannot be greater than upper).
Return an array of the type indicated by type with elements the same as those of list.
The argument dimspec determines the number of dimensions of the array and their lower bounds. When dimspec is an exact integer, it gives the number of dimensions directly and all lower bounds are zero. When it is a list of exact integers, then each element is the lower index bound of a dimension, and there will be as many dimensions as elements in the list.
Return the type of array. This is the `vectag' used for printing array (or
#t
for ordinary arrays) and can be used withmake-typed-array
to create an array of the same kind as array.
Return the element at
(idx ...)
in array.(define a (make-array 999 '(1 2) '(3 4))) (array-ref a 2 4) => 999
Return
#t
if the given index would be acceptable toarray-ref
.(define a (make-array #f '(1 2) '(3 4))) (array-in-bounds? a 2 3) => #t (array-in-bounds? a 0 0) => #f
Set the element at
(idx ...)
in array to obj. The return value is unspecified.(define a (make-array #f '(0 1) '(0 1))) (array-set! a #t 1 1) a => #2((#f #f) (#f #t))
dim1, dim2 ... should be nonnegative integers less than the rank of array.
enclose-array
returns an array resembling an array of shared arrays. The dimensions of each shared array are the same as the dimth dimensions of the original array, the dimensions of the outer array are the same as those of the original array that did not match a dim.An enclosed array is not a general Scheme array. Its elements may not be set using
array-set!
. Two references to the same element of an enclosed array will beequal?
but will not in general beeq?
. The value returned byarray-prototype
when given an enclosed array is unspecified.For example,
(enclose-array '#3(((a b c) (d e f)) ((1 2 3) (4 5 6))) 1) => #<enclosed-array (#1(a d) #1(b e) #1(c f)) (#1(1 4) #1(2 5) #1(3 6))> (enclose-array '#3(((a b c) (d e f)) ((1 2 3) (4 5 6))) 1 0) => #<enclosed-array #2((a 1) (d 4)) #2((b 2) (e 5)) #2((c 3) (f 6))>
Return a list of the bounds for each dimenson of array.
array-shape
gives(
lower upper)
for each dimension.array-dimensions
instead returns just upper+1 for dimensions with a 0 lower bound. Both are suitable as input tomake-array
.For example,
(define a (make-array 'foo '(-1 3) 5)) (array-shape a) => ((-1 3) (0 4)) (array-dimensions a) => ((-1 3) 5)
Return a list consisting of all the elements, in order, of array.
Copy every element from vector or array src to the corresponding element of dst. dst must have the same rank as src, and be at least as large in each dimension. The return value is unspecified.
Store fill in every element of array. The value returned is unspecified.
Return
#t
if all arguments are arrays with the same shape, the same type, and have corresponding elements which are eitherequal?
orarray-equal?
. This function differs fromequal?
in that a one dimensional shared array may be array-equal? but not equal? to a vector or uniform vector.
Set each element of the dst array to values obtained from calls to proc. The value returned is unspecified.
Each call is
(
proc elem1...
elemN)
, where each elem is from the corresponding src array, at the dst index.array-map-in-order!
makes the calls in row-major order,array-map!
makes them in an unspecified order.The src arrays must have the same number of dimensions as dst, and must have a range for each dimension which covers the range in dst. This ensures all dst indices are valid in each src.
Apply proc to each tuple of elements of src1 ... srcN, in row-major order. The value returned is unspecified.
Set each element of the dst array to values returned by calls to proc. The value returned is unspecified.
Each call is
(
proc i1...
iN)
, where i1...iN is the destination index, one parameter for each dimension. The order in which the calls are made is unspecified.For example, to create a 4x4 matrix representing a cyclic group,
/ 0 1 2 3 \ | 1 2 3 0 | | 2 3 0 1 | \ 3 0 1 2 /(define a (make-array #f 4 4)) (array-index-map! a (lambda (i j) (modulo (+ i j) 4)))
Attempt to read all elements of ura, in lexicographic order, as binary objects from port-or-fdes. If an end of file is encountered, the objects up to that point are put into ura (starting at the beginning) and the remainder of the array is unchanged.
The optional arguments start and end allow a specified region of a vector (or linearized array) to be read, leaving the remainder of the vector unchanged.
uniform-array-read!
returns the number of objects read. port-or-fdes may be omitted, in which case it defaults to the value returned by(current-input-port)
.
Writes all elements of ura as binary objects to port-or-fdes.
The optional arguments start and end allow a specified region of a vector (or linearized array) to be written.
The number of objects actually written is returned. port-or-fdes may be omitted, in which case it defaults to the value returned by
(current-output-port)
.