6.7 Construction
syntax
(array #[#[...] ...] maybe-type-ann)
maybe-type-ann =
| : type
The vector syntax #[...] delimits rows. These may be nested to any depth, and must have a rectangular shape. Using square parentheses is not required, but is encouraged to help visually distinguish array contents from array indexes and other vectors. (See the examples for indexes-array for an illustration.)
Examples: | ||||||||||||||
|
> (list 1 2 3) - : (Listof Positive-Byte) [more precisely: (List One Positive-Byte Positive-Byte)]
'(1 2 3)
> (array #[1 2 3]) - : (Array Positive-Byte)
(array #[1 2 3])
> ((inst list Real) 1 2 3) - : (Listof Real)
'(1 2 3)
> ((inst array Real) #[1 2 3]) eval:125:0: array: not allowed as an expression
in: array
> (array #[1 2 3] : Real) - : (Array Real)
(array #[1 2 3])
> (ann (array #[1 2 3]) (Array Real)) - : (Array Real)
(array #[1 2 3])
> #(this is okay) - : (Vector Symbol Symbol Symbol)
'#(this is okay)
> (array #[not okay]) eval:129:0: Type Checker: missing type for top-level
identifier;
either undefined or missing a type annotation
identifier: okay
in: #(not okay)
> (array #['this 'is 'okay]) - : (Array (U 'this 'is 'okay))
(array #['this 'is 'okay])
> (array #['#(an) '#(array) '#(of) '#(vectors)]) - : (Array (Vector Symbol))
(array #['#(an) '#(array) '#(of) '#(vectors)])
Arrays returned by array are strict. Another way to create immutable, strict arrays from literal data is to use list->array.
syntax
(mutable-array #[#[...] ...] maybe-type-ann)
maybe-type-ann =
| : type
> (define arr (mutable-array #[0 1 2 3]))
> arr - : (Mutable-Array Integer)
(mutable-array #[0 1 2 3])
> (array-set! arr #(0) 10)
> arr - : (Mutable-Array Integer)
(mutable-array #[10 1 2 3])
> (define arr (mutable-array #[0 1 2 3] : Real))
> arr - : (Mutable-Array Real)
(mutable-array #[0 1 2 3])
> (array-set! arr #(0) 10.0)
> arr - : (Mutable-Array Real)
(mutable-array #[10.0 1 2 3])
Another way to create mutable arrays from literal data is to use vector->array.
procedure
(make-array ds value) → (Array A)
ds : In-Indexes value : A
Examples: | |||||||||
|
procedure
(build-array ds proc) → (Array A)
ds : In-Indexes proc : (Indexes -> A)
procedure
(array->mutable-array arr) → (Mutable-Array A)
arr : (Array A)
procedure
(mutable-array-copy arr) → (Mutable-Array A)
arr : (Mutable-Array A)
procedure
(indexes-array ds) → (Array Indexes)
ds : In-Indexes
Examples: | ||||||||||||
|
procedure
(index-array ds) → (Array Index)
ds : In-Indexes
Examples: | ||||||
|
procedure
(axis-index-array ds axis) → (Array Index)
ds : In-Indexes axis : Integer
Examples: | |||||||||||||
|
procedure
(diagonal-array dims axes-length on-value off-value) → (Array A) dims : Integer axes-length : Integer on-value : A off-value : A
Example: | |||||||||||
|