Accessors — Reading and writing array elements
cl_object ecl_aref(
cl_object array,
cl_index row_major_index)
;
cl_object ecl_aset(
cl_object array,
cl_index row_major_index,
cl_object new_value)
;
cl_object ecl_aref1(
cl_object vector,
cl_index row_major_index)
;
cl_object ecl_aset1(
cl_object vector,
cl_index row_major_index,
cl_object new_value)
;
ecl_aref
accesses an array using the supplied row_major_index
, checking the array bounds and returning a Lisp object for the value at that position. ecl_aset
does the converse, storing a Lisp value at the given row_major_index
.
The first argument to ecl_aref
or ecl_aset
is an array of any number of dimensions. For an array of rank N
and dimensions d1
, d2
... up to dN
, the row major index associated to the indices (i1,i2,...iN)
is computed using the formula i1+d1*(i2+d3*(i3+...))
.
ecl_aref1
and ecl_aset1
are specialized versions that only work with one-dimensional arrays or vectors. They verify that the first argument is indeed a vector.
All functions above check that the index does not exceed the array bounds, that the values match the array element type and that the argument is an array (or a vector). If these conditions are not met, a type error is signaled.