Re: Lexicographical access to arrays
Per Bothner 09 Apr 2026 19:46 UTC
On 4/9/26 11:59, John Cowan wrote:
> Common Lisp has an accessor (array-major-aref a n) which retrieves the
> nth element of an array enumerated in lexicographical order. As such,
> it also comes with a setter: (setf (array-major-aref a n) x) where x
> is the new value. Setf is equivalent to SRFI 17's version of `set!`,
> and replaces essentially all mutator functions in CL (rplaca and
> rplacd are still there for hysterical raisins).
>
> It seems partly possible to emulate this using array-body and
> array-indexer, but then you have to know what kind of body you have
> (vector, @vector, or something else). I think it would be worth
> adding these. (Maybe there's a way to do them already, in which case
> it would be worth pointing it out in 231bis.)
SRFI-164 have array-flatten and array->vector:
Return a vector consisting of the elements of the array in row-major-order.
The result of array-flatten is a fresh (mutable and simple) copy, not a view.
The result of array->vector is a view: If array is mutable, then modifying
array changes the flattened result and vice versa.
If array is 'simple', array->vector returns the 'underlying vector;.
--
--Per Bothner
xxxxxx@bothner.com http://per.bothner.com/'