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.

— Scheme Procedure: **array?**` obj`

— C Function:**scm_array_p** (`obj, unused`)

— C Function:

Return

`#t`

if theobjis 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.

— Scheme Procedure: **typed-array?**` obj type`

— C Function:**scm_typed_array_p** (`obj, type`)

— C Function:

Return

`#t`

if theobjis an array of typetype, and`#f`

if not.

— C Function: int **scm_is_typed_array** (`SCM obj, SCM type`)

Return

`0`

if theobjis an array of typetype, and`1`

if not.

— Scheme Procedure: **make-array**` fill bound ...`

— C Function:**scm_make_array** (`fill, bounds`)

— C Function:

Equivalent to

`(make-typed-array #t`

fillbound`...)`

.

— Scheme Procedure: **make-typed-array**` type fill bound ...`

— C Function:**scm_make_typed_array** (`type, fill, bounds`)

— C Function:

Create and return an array that has as many dimensions as there are

bounds and (maybe) fill it withfill.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`

fortypewill create an array that uses a`f64vector`

for storing its elements, and`a`

will use a string.When

fillis not the specialunspecifiedvalue, the new array is filled withfill. Otherwise, the initial contents of the array is unspecified. The specialunspecifiedvalue is stored in the variable`*unspecified*`

so that for example`(make-typed-array 'u32 *unspecified* 4)`

creates a uninitialized`u32`

vector of length 4.Each

boundmay be a positive non-zero integerN, in which case the index for that dimension can range from 0 throughN-1; or an explicit index range specifier in the form`(LOWER UPPER)`

, where bothlowerandupperare integers, possibly less than zero, and possibly the same number (however,lowercannot be greater thanupper).

— Scheme Procedure: **list->typed-array**` type dimspec list`

— C Function:**scm_list_to_typed_array** (`type, dimspec, list`)

— C Function:

Return an array of the type indicated by

typewith elements the same as those oflist.The argument

dimspecdetermines the number of dimensions of the array and their lower bounds. Whendimspecis 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.

— Scheme Procedure: **array-type**` array`

Return the type of

array. This is the `vectag' used for printingarray(or`#t`

for ordinary arrays) and can be used with`make-typed-array`

to create an array of the same kind asarray.

— Scheme Procedure: **array-ref**` array idx ...`

Return the element at

`(idx ...)`

inarray.(define a (make-array 999 '(1 2) '(3 4))) (array-ref a 2 4) ⇒ 999

— Scheme Procedure: **array-in-bounds?**` array idx ...`

— C Function:**scm_array_in_bounds_p** (`array, idxlist`)

— C Function:

Return

`#t`

if the given index would be acceptable to`array-ref`

.(define a (make-array #f '(1 2) '(3 4))) (array-in-bounds? a 2 3) ⇒ #t (array-in-bounds? a 0 0) ⇒ #f

— Scheme Procedure: **array-set!**` array obj idx ...`

— C Function:**scm_array_set_x** (`array, obj, idxlist`)

— C Function:

Set the element at

`(idx ...)`

inarraytoobj. 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))

— Scheme Procedure: **enclose-array**` array dim1 ...`

— C Function:**scm_enclose_array** (`array, dimlist`)

— C Function:

dim1,dim2... should be nonnegative integers less than the rank ofarray.`enclose-array`

returns an array resembling an array of shared arrays. The dimensions of each shared array are the same as thedimth dimensions of the original array, the dimensions of the outer array are the same as those of the original array that did not match adim.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 be`equal?`

but will not in general be`eq?`

. The value returned by`array-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))>

— Scheme Procedure: **array-shape**` array`

— Scheme Procedure:**array-dimensions**` array`

— C Function:**scm_array_dimensions** (`array`)

— Scheme Procedure:

— C Function:

Return a list of the bounds for each dimenson of

array.

`array-shape`

gives`(`

lowerupper`)`

for each dimension.`array-dimensions`

instead returns justupper+1 for dimensions with a 0 lower bound. Both are suitable as input to`make-array`

.For example,

(define a (make-array 'foo '(-1 3) 5)) (array-shape a) ⇒ ((-1 3) (0 4)) (array-dimensions a) ⇒ ((-1 3) 5)

— Scheme Procedure: **array->list**` array`

— C Function:**scm_array_to_list** (`array`)

— C Function:

Return a list consisting of all the elements, in order, of

array.

— Scheme Procedure: **array-copy!**` src dst`

— Scheme Procedure:**array-copy-in-order!**` src dst`

— C Function:**scm_array_copy_x** (`src, dst`)

— Scheme Procedure:

— C Function:

Copy every element from vector or array

srcto the corresponding element ofdst.dstmust have the same rank assrc, and be at least as large in each dimension. The return value is unspecified.

— Scheme Procedure: **array-fill!**` array fill`

— C Function:**scm_array_fill_x** (`array, fill`)

— C Function:

Store

fillin every element ofarray. The value returned is unspecified.

— Scheme Procedure: **array-equal?**` array1 array2 ...`

Return

`#t`

if all arguments are arrays with the same shape, the same type, and have corresponding elements which are either`equal?`

or`array-equal?`

. This function differs from`equal?`

(see Equality) in that a one dimensional shared array may be`array-equal?`

but not`equal?`

to a vector or uniform vector.

— Scheme Procedure: **array-map!**` dst proc src1 ... srcN`

— Scheme Procedure:**array-map-in-order!**` dst proc src1 ... srcN`

— C Function:**scm_array_map_x** (`dst, proc, srclist`)

— Scheme Procedure:

— C Function:

Set each element of the

dstarray to values obtained from calls toproc. The value returned is unspecified.Each call is

`(`

procelem1`...`

elemN`)`

, where eachelemis from the correspondingsrcarray, at thedstindex.`array-map-in-order!`

makes the calls in row-major order,`array-map!`

makes them in an unspecified order.The

srcarrays must have the same number of dimensions asdst, and must have a range for each dimension which covers the range indst. This ensures alldstindices are valid in eachsrc.

— Scheme Procedure: **array-for-each**` proc src1 ... srcN`

— C Function:**scm_array_for_each** (`proc, src1, srclist`)

— C Function:

Apply

procto each tuple of elements ofsrc1...srcN, in row-major order. The value returned is unspecified.

— Scheme Procedure: **array-index-map!**` dst proc`

— C Function:**scm_array_index_map_x** (`dst, proc`)

— C Function:

Set each element of the

dstarray to values returned by calls toproc. The value returned is unspecified.Each call is

`(`

proci1`...`

iN`)`

, wherei1...iNis 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)))

— Scheme Procedure: **uniform-array-read!**` ra `[`port_or_fd `[`start `[`end`]]]

— C Function:**scm_uniform_array_read_x** (`ra, port_or_fd, start, end`)

— C Function:

Attempt to read all elements of

ura, in lexicographic order, as binary objects fromport-or-fdes. If an end of file is encountered, the objects up to that point are put intoura(starting at the beginning) and the remainder of the array is unchanged.The optional arguments

startandendallow 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-fdesmay be omitted, in which case it defaults to the value returned by`(current-input-port)`

.

— Scheme Procedure: **uniform-array-write**` v `[`port_or_fd `[`start `[`end`]]]

— C Function:**scm_uniform_array_write** (`v, port_or_fd, start, end`)

— C Function:

Writes all elements of

uraas binary objects toport-or-fdes.The optional arguments

startandendallow a specified region of a vector (or linearized array) to be written.The number of objects actually written is returned.

port-or-fdesmay be omitted, in which case it defaults to the value returned by`(current-output-port)`

.