(rontolisp) docs
← cl Package Functions

aref

(aref array &rest subscripts)

Returns the element of array at the given 0-based subscripts, one per dimension (none for a rank-0 array, one for a rank-1 vector, two for a rank-2 array, and so on). A string is a rank-1 character array, so (aref s i) reads like char (writing a string element goes through the schar/char setf place instead). Flat rank-independent access is available via row-major-aref. To modify an element, use aref as a setf place: (setf (aref array i j) value), which also works with incf/decf/push. #'aref is a first-class function value, so it can be passed to mapcar/funcall like any other function.

Each subscript must lie within its own dimension: one that does not signals a type-error whose datum is the subscript and whose expected type is (integer 0 (d)), d being that dimension, reported as AREF: The value 3 is not of type (INTEGER 0 (3)) on every backend (on the wasm-GC backends in a program with a catching form; without one it traps). A column past its dimension is out of range even when the row-major index it would fold to is not. A store reports as (SETF AREF), after the stored value is evaluated and checked. An array that is no array signals a type-error whose expected type is array: AREF: The value 5 is not of type ARRAY. A subscript count other than the array's rank signals a type-error whose datum is the array and whose expected type is the array of the rank the subscripts spell: vector for one subscript, (array * nil) for none, (array * (* *)) for two. On a 2x2 array, (aref m 1) reports AREF: The value #2A((1 2) (3 4)) is not of type VECTOR, a store under (SETF AREF) (on the wasm-GC backends, again, in a program with a catching form). Every argument is evaluated first; then each subscript's type is checked, then the array and its rank, then a stored value, then the bounds. #'aref checks in the same order.