Lexicographical access to arrays John Cowan (09 Apr 2026 18:59 UTC)
Re: Lexicographical access to arrays Per Bothner (09 Apr 2026 19:47 UTC)
Re: Lexicographical access to arrays Alex Shinn (09 Apr 2026 23:48 UTC)
Re: Lexicographical access to arrays Bradley Lucier (10 Apr 2026 00:22 UTC)
Re: Lexicographical access to arrays Per Bothner (10 Apr 2026 01:48 UTC)
Re: Lexicographical access to arrays John Cowan (10 Apr 2026 05:52 UTC)
Re: Lexicographical access to arrays Bradley Lucier (10 Apr 2026 15:33 UTC)
Re: Lexicographical access to arrays Bradley Lucier (10 Apr 2026 15:36 UTC)
Re: Lexicographical access to arrays Bradley Lucier (11 Apr 2026 00:32 UTC)
Re: Lexicographical access to arrays John Cowan (11 Apr 2026 04:03 UTC)
Re: Lexicographical access to arrays Bradley Lucier (11 Apr 2026 17:37 UTC)

Re: Lexicographical access to arrays Bradley Lucier 10 Apr 2026 00:22 UTC

On 4/9/26 14: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.)

I don't know Common Lisp.  I'll repeat, I don't know Common Lisp.

I've looked at the Common Lisp spec for arrays, including "The Arrays
Dictionary"

https://www.lispworks.com/documentation/HyperSpec/Body/c_arrays.htm

It appears to me from reading the spec that array elements are stored
contiguously in increasing memory locations for CL arrays.  (CL arrays
can be "displaced", which leaves elements in order.)  That makes
row-major-aref useful in CL.

"Sharing" specialized arrays as in Kawa (and, to be clear, I don't know
Kawa) and SRFI 231 (and NumPy and Racket and ...) means that elements
that are "adjacent" in row-major order can be widely dispersed in memory.

And that doesn't even get into "generalized" arrays.

So the only way to implement something like array-major-aref would be
something like Kawa's rowMajorToEffectiveIndex in
./gnu/lists/Arrays.java (and speaking of things I don't know, I don't
know Java) which would take your number n and compute a multi-index

i_0 i_1 ... i_d-1

by finding the remainder and quotient of n by successive dimension sizes
("width"s in SRFI 231).

That is not an efficient way to access array elements.  To do something
to all array elements in row-major order, it would be better to use a
bulk array operation like array-for-each (or interval-for-each if you
want to work at the multi-index level), which steps through the array
elements in row-major order.