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 Note: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)'.
- primitive: array? v [prot]
Returns `#t' if the OBJ is an array, and `#f' if not.
The PROTOTYPE argument is used with uniform arrays and is described
elsewhere.
- procedure: make-uniform-array prototype bound1 bound2 ...
Creates and returns a uniform array of type corresponding to
PROTOTYPE that has as many dimensions as there are BOUNDs and
fills it with PROTOTYPE.
- primitive: array-prototype ra
Returns an object that would produce an array of the same type as
ARRAY, if used as the PROTOTYPE for `make-uniform-array'.
- primitive: list->uniform-array ndim prot lst
- procedure: list->uniform-vector prot lst
Returns a uniform array of the type indicated by prototype PROT
with elements the same as those of LST. Elements must be of the
appropriate type, no coercions are done.
- primitive: uniform-vector-fill! uve fill
Stores FILL in every element of UVE. The value returned is
unspecified.
- primitive: uniform-vector-length v
Returns the number of elements in UVE.
- primitive: dimensions->uniform-array dims prot [fill]
- primitive: make-uniform-vector length prototype [fill]
Creates and returns a uniform array or vector of type
corresponding to PROTOTYPE with dimensions DIMS or length LENGTH.
If FILL is supplied, it's used to fill the array, otherwise
PROTOTYPE is used.
- primitive: uniform-array-read! ra [port_or_fd [start [end]]]
- primitive: uniform-vector-read! uve [port-or-fdes] [start] [end]
Attempts to read all elements of URA, in lexicographic order, as
binary objects from PORT-OR-FDES. If an end of file is
encountered during uniform-array-read! the objects up to that
point only are put into URA (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.
`uniform-array-read!' returns the number of objects read.
PORT-OR-FDES may be omitted, in which case it defaults to the value
returned by `(current-input-port)'.
- primitive: uniform-array-write v [port_or_fd [start [end]]]
- primitive: uniform-vector-write uve [port-or-fdes] [start] [end]
Writes all elements of URA as binary objects to PORT-OR-FDES.
The optional arguments START and END allow a specified region of a
vector (or linearized array) to be written.
The number of objects actually written is returned. PORT-OR-FDES
may be omitted, in which case it defaults to the value returned by
`(current-output-port)'.