Next: , Previous: Array Mapping, Up: Arrays


22.6.3 Uniform Arrays

Uniform arrays have elements all of the same type and occupy less storage than conventional arrays. Uniform arrays with a single zero-based dimension are also known as uniform vectors. The procedures in this section can also be used on conventional arrays, vectors, bit-vectors and strings.

When creating a uniform array, the type of data to be stored is indicated with a prototype argument. The following table lists the types available and example prototypes:

     prototype           type                       printing character
     
     #t             boolean (bit-vector)                    b
     #\a            char (string)                           a
     #\nul          byte (integer)                          y
     's             short (integer)                         h
     1              unsigned long (integer)                 u
     -1             signed long (integer)                   e
     'l             signed long long (integer)              l
     1.0            float (single precision)                s
     1/3            double (double precision float)         i
     0+i            complex (double precision)              c
     ()             conventional vector

Unshared uniform arrays of characters with a single zero-based dimension are identical to strings:

     (make-uniform-array #\a 3)
     ⇒ "aaa"

Unshared uniform arrays of booleans with a single zero-based dimension are identical to bit-vectors.

     (make-uniform-array #t 3)
     ⇒ #*111

Other uniform vectors are written in a form similar to that of vectors, except that a single character from the above table is put between # and (. For example, a uniform vector of signed long integers is displayed in the form '#e(3 5 9).

— Scheme Procedure: array? obj [prot]

Return #t iff the obj is an array. The optional second arg prot is used with uniform arrays and must be equal? to the value described in the prototype table (see Uniform Arrays).

— Scheme Procedure: make-uniform-array prototype [bound ...]

Create and return a uniform array of type corresponding to prototype that has as many dimensions as there are bounds and fill it with prototype.

— Scheme Procedure: array-prototype array
— C Function: scm_array_prototype (array)

Return an object that would produce an array of the same type as array, if used as the prototype for make-uniform-array.

— Scheme Procedure: list->uniform-array ndim prot lst
— C Function: scm_list_to_uniform_array (ndim, prot, lst)

Return a uniform array with ndim dimensions, of the type indicated by prototype prot, and with elements the same as those of lst. Elements must be of the appropriate type; no coercions are done.

— Scheme Procedure: list->array ndim lst

Equivalent to (list->uniform-array ndim '() lst).

— Scheme Procedure: list->uniform-vector prot lst

Equivalent to (list->uniform-array 1 prot lst).

— Scheme Procedure: uniform-vector-fill! uve fill

Store fill in every element of uve. The return value is unspecified.

— Scheme Procedure: uniform-vector-length v
— C Function: scm_uniform_vector_length (v)

Return the number of elements in uniform vector v.

— Scheme Procedure: dimensions->uniform-array dims prot [fill]
— C Function: scm_dimensions_to_uniform_array (dims, prot, fill) |2 |1 |0

Create and return a uniform array or vector of type corresponding to prototype prot with dimensions dims, either an integer, in which case it is interpreted as the vector length; or a list, in which case each element is either an integer or a sublist of the form (lower upper). If fill is supplied, use it to fill the array, otherwise use prot.

— Scheme Procedure: uniform-array-read! ra [port_or_fd [start [end]]]
— Scheme Procedure: uniform-vector-read! ra [port_or_fd [start [end]]]
— C Function: scm_uniform_array_read_x (ra, port_or_fd, start, end) |1 |3 |0

Attempt to assign all elements of array, in lexicographic order, as binary objects read from port/fdes (or the current input port, if omitted). If an end of file is encountered during reading, the objects up to that point only are put into array (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.

Return the number of objects read.

-sig (array [port/fdes [start [end]]])

— Scheme Procedure: uniform-array-write array [port/fdes [start [end]]]
— Scheme Procedure: uniform-vector-write array [port/fdes [start [end]]]
— C Function: scm_uniform_array_write (array, port/fdes, start, end)

Write all elements of array as binary objects to port/fdes (or the current output port, if omitted).

The optional arguments start and end allow a specified region of a vector (or linearized array) to be written.

Return the number of objects actually written.