Next: , Up: Arrays   [Contents][Index]


6.7.5.1 Array Syntax

An array is displayed as # followed by its rank, followed by a tag that describes the underlying vector, optionally followed by information about its shape, and finally followed by the cells, organized into dimensions using parentheses.

In more words, the array tag is of the form

  #<rank><vectag><@lower><:len><@lower><:len>...

where <rank> is a positive integer in decimal giving the rank of the array. It is omitted when the rank is 1 and the array is non-shared and has zero-origin (see below). For shared arrays and for a non-zero origin, the rank is always printed even when it is 1 to distinguish them from ordinary vectors.

The <vectag> part is the tag for a uniform numeric vector, like u8, s16, etc, b for bitvectors, or a for strings. It is empty for ordinary vectors.

The <@lower> part is a ‘@’ character followed by a signed integer in decimal giving the lower bound of a dimension. There is one <@lower> for each dimension. When all lower bounds are zero, all <@lower> parts are omitted.

The <:len> part is a ‘:’ character followed by an unsigned integer in decimal giving the length of a dimension. Like for the lower bounds, there is one <:len> for each dimension, and the <:len> part always follows the <@lower> part for a dimension. Lengths are only then printed when they can’t be deduced from the nested lists of elements of the array literal, which can happen when at least one length is zero.

As a special case, an array of rank 0 is printed as #0<vectag>(<scalar>), where <scalar> is the result of printing the single element of the array.

Thus,

#(1 2 3)

is an ordinary array of rank 1 with lower bound 0 in dimension 0. (I.e., a regular vector.)

#@2(1 2 3)

is an ordinary array of rank 1 with lower bound 2 in dimension 0.

#2((1 2 3) (4 5 6))

is a non-uniform array of rank 2; a 2x3 matrix with index ranges 0..1 and 0..2.

#u32(0 1 2)

is a uniform u8 array of rank 1.

#2u32@2@3((1 2) (2 3))

is a uniform u32 array of rank 2 with index ranges 2..3 and 3..4.

#2()

is a two-dimensional array with index ranges 0..-1 and 0..-1, i.e. both dimensions have length zero.

#2:0:2()

is a two-dimensional array with index ranges 0..-1 and 0..1, i.e. the first dimension has length zero, but the second has length 2.

#0(12)

is a rank-zero array with contents 12.

In addition, bytevectors are also arrays, but use a different syntax (see Bytevectors):

#vu8(1 2 3)

is a 3-byte long bytevector, with contents 1, 2, 3.


Next: , Up: Arrays   [Contents][Index]