Next: Strings, Previous: Characters, Up: Lisp objects
An array is an aggregate of data of a common type, which can be accessed with one or more nonnegative indices. ECL stores arrays as a C structure with a pointer to the region of memory which contains the actual data. The cell of an array datatype varies depending on whether it is a vector, a bytevector, a multidimensional array or a string.
If x contains a vector, you can access the following fields:
x->vector.elttype
x->vector.dim
x->vector.fillp
x->vector.self
x->vector.elltype
x->vector.hasfillp
x->vector.fillp
can be smaller than x->vector.dim
.
If x contains a multidimensional array, the cell elements become
x->array.elttype
x->array.dim
x->array.rank
x->array.dims[]
x->array.dim[0]
to x->array.dim[x->array.rank-1]
.
x->array.self
x->array.elltype
.
x->array.rank
x->vector.fillp
can be smaller than x->vector.dim
.
Each array is of an specialized type which is the type of the elements of the
array. ECL has arrays only a few following specialized types, and for each
of these types there is a C integer which is the corresponding value of
x->array.elttype
or x->vector.elttype
. We list those types
together with the C constant that denotes that type:
aet_object
aet_ch
aet_fix
aet_bit
aet_sf
aet_df
Returns the element type of the array o, which can be a string, a bitvector, vector, or a multidimensional array. For example, the code
array_elttype(c_string_to_object("\"AAA\""))
returnsaet_ch
, while thearray_elttype(c_string_to_object("#(A B C)"))
returnsaet_object
.
These functions are used to retrieve and set the elements of an array. The elements are accessed with one index, index, as in the lisp function
ROW-MAJOR-AREF
. For examplecl_object array = c_string_to_object("#2A((1 2) (3 4))"); cl_object x = aref(array, 3); cl_print(1, x); /* Outputs 4 */ aset(array, 3, MAKE_FIXNUM(5)); cl_print(1, array); /* Outputs #2A((1 2) (3 5)) */
These functions are similar to
aref
andaset
, but they operate on vectors.cl_object array = c_string_to_object("#(1 2 3 4)"); cl_object x = aref1(array, 3); cl_print(1, x); /* Outputs 4 */ aset1(array, 3, MAKE_FIXNUM(5)); cl_print(1, array); /* Outputs #(1 2 3 5) */