Next: , Previous: Data Structures, Up: Data Structures

#### 7.1.1 Arrays

`(require 'array)` or `(require 'srfi-63)`

— Function: array? obj

Returns `#t` if the obj is an array, and `#f` if not.

Note: Arrays are not disjoint from other Scheme types. Vectors and possibly strings also satisfy `array?`. A disjoint array predicate can be written:

```     (define (strict-array? obj)
(and (array? obj) (not (string? obj)) (not (vector? obj))))
```
— Function: equal? obj1 obj2

Returns `#t` if obj1 and obj2 have the same rank and dimensions and the corresponding elements of obj1 and obj2 are `equal?`.

`equal?` recursively compares the contents of pairs, vectors, strings, and arrays, applying `eqv?` on other objects such as numbers and symbols. A rule of thumb is that objects are generally `equal?` if they print the same. `equal?` may fail to terminate if its arguments are circular data structures.

```          (equal? 'a 'a)                             ⇒  #t
(equal? '(a) '(a))                         ⇒  #t
(equal? '(a (b) c)
'(a (b) c))                        ⇒  #t
(equal? "abc" "abc")                       ⇒  #t
(equal? 2 2)                               ⇒  #t
(equal? (make-vector 5 'a)
(make-vector 5 'a))                ⇒  #t
(equal? (make-array (A:fixN32b 4) 5 3)
(make-array (A:fixN32b 4) 5 3))    ⇒  #t
(equal? (make-array '#(foo) 3 3)
(make-array '#(foo) 3 3))          ⇒  #t
(equal? (lambda (x) x)
(lambda (y) y))                    ⇒  unspecified
```
— Function: array-rank obj

Returns the number of dimensions of obj. If obj is not an array, 0 is returned.

— Function: array-dimensions array

Returns a list of dimensions.

```          (array-dimensions (make-array '#() 3 5))
⇒ (3 5)
```
— Function: make-array prototype k1 ...

Creates and returns an array of type prototype with dimensions k1, ... and filled with elements from prototype. prototype must be an array, vector, or string. The implementation-dependent type of the returned array will be the same as the type of prototype; except if that would be a vector or string with rank not equal to one, in which case some variety of array will be returned.

If the prototype has no elements, then the initial contents of the returned array are unspecified. Otherwise, the returned array will be filled with the element at the origin of prototype.

— Function: create-array prototype k1 ...

`create-array` is an alias for `make-array`.

— Function: make-shared-array array mapper k1 ...

`make-shared-array` can be used to create shared subarrays of other arrays. The mapper is a function that translates coordinates in the new array into coordinates in the old array. A mapper must be linear, and its range must stay within the bounds of the old array, but it can be otherwise arbitrary. A simple example:

```          (define fred (make-array '#(#f) 8 8))
(define freds-diagonal
(make-shared-array fred (lambda (i) (list i i)) 8))
(array-set! freds-diagonal 'foo 3)
(array-ref fred 3 3)
⇒ FOO
(define freds-center
(make-shared-array fred (lambda (i j) (list (+ 3 i) (+ 3 j)))
2 2))
(array-ref freds-center 0 0)
⇒ FOO
```
— Function: list->array rank proto list

list must be a rank-nested list consisting of all the elements, in row-major order, of the array to be created.

`list->array` returns an array of rank rank and type proto consisting of all the elements, in row-major order, of list. When rank is 0, list is the lone array element; not necessarily a list.

```          (list->array 2 '#() '((1 2) (3 4)))
⇒ #2A((1 2) (3 4))
(list->array 0 '#() 3)
⇒ #0A 3
```
— Function: array->list array

Returns a rank-nested list consisting of all the elements, in row-major order, of array. In the case of a rank-0 array, `array->list` returns the single element.

```          (array->list #2A((ho ho ho) (ho oh oh)))
⇒ ((ho ho ho) (ho oh oh))
(array->list #0A ho)
⇒ ho
```
— Function: vector->array vect proto dim1 ...

vect must be a vector of length equal to the product of exact nonnegative integers dim1, ....

`vector->array` returns an array of type proto consisting of all the elements, in row-major order, of vect. In the case of a rank-0 array, vect has a single element.

```          (vector->array #(1 2 3 4) #() 2 2)
⇒ #2A((1 2) (3 4))
(vector->array '#(3) '#())
⇒ #0A 3
```
— Function: array->vector array

Returns a new vector consisting of all the elements of array in row-major order.

```          (array->vector #2A ((1 2)( 3 4)))
⇒ #(1 2 3 4)
(array->vector #0A ho)
⇒ #(ho)
```
— Function: array-in-bounds? array index1 ...

Returns `#t` if its arguments would be acceptable to `array-ref`.

— Function: array-ref array k1 ...

Returns the (k1, ...) element of array.

— Procedure: array-set! array obj k1 ...

Stores obj in the (k1, ...) element of array. The value returned by `array-set!` is unspecified.

These functions return a prototypical uniform-array enclosing the optional argument (which must be of the correct type). If the uniform-array type is supported by the implementation, then it is returned; defaulting to the next larger precision type; resorting finally to vector.

— Function: A:floC128b z
— Function: A:floC128b

Returns an inexact 128.bit flonum complex uniform-array prototype.

— Function: A:floC64b z
— Function: A:floC64b

Returns an inexact 64.bit flonum complex uniform-array prototype.

— Function: A:floC32b z
— Function: A:floC32b

Returns an inexact 32.bit flonum complex uniform-array prototype.

— Function: A:floC16b z
— Function: A:floC16b

Returns an inexact 16.bit flonum complex uniform-array prototype.

— Function: A:floR128b x
— Function: A:floR128b

Returns an inexact 128.bit flonum real uniform-array prototype.

— Function: A:floR64b x
— Function: A:floR64b

Returns an inexact 64.bit flonum real uniform-array prototype.

— Function: A:floR32b x
— Function: A:floR32b

Returns an inexact 32.bit flonum real uniform-array prototype.

— Function: A:floR16b x
— Function: A:floR16b

Returns an inexact 16.bit flonum real uniform-array prototype.

— Function: A:floR128d q
— Function: A:floR128d

Returns an exact 128.bit decimal flonum rational uniform-array prototype.

— Function: A:floR64d q
— Function: A:floR64d

Returns an exact 64.bit decimal flonum rational uniform-array prototype.

— Function: A:floR32d q
— Function: A:floR32d

Returns an exact 32.bit decimal flonum rational uniform-array prototype.

— Function: A:fixZ64b n
— Function: A:fixZ64b

Returns an exact binary fixnum uniform-array prototype with at least 64 bits of precision.

— Function: A:fixZ32b n
— Function: A:fixZ32b

Returns an exact binary fixnum uniform-array prototype with at least 32 bits of precision.

— Function: A:fixZ16b n
— Function: A:fixZ16b

Returns an exact binary fixnum uniform-array prototype with at least 16 bits of precision.

— Function: A:fixZ8b n
— Function: A:fixZ8b

Returns an exact binary fixnum uniform-array prototype with at least 8 bits of precision.

— Function: A:fixN64b k
— Function: A:fixN64b

Returns an exact non-negative binary fixnum uniform-array prototype with at least 64 bits of precision.

— Function: A:fixN32b k
— Function: A:fixN32b

Returns an exact non-negative binary fixnum uniform-array prototype with at least 32 bits of precision.

— Function: A:fixN16b k
— Function: A:fixN16b

Returns an exact non-negative binary fixnum uniform-array prototype with at least 16 bits of precision.

— Function: A:fixN8b k
— Function: A:fixN8b

Returns an exact non-negative binary fixnum uniform-array prototype with at least 8 bits of precision.

— Function: A:bool bool
— Function: A:bool

Returns a boolean uniform-array prototype.