Re: Common Lisp `row-major-aref`
Bradley Lucier 09 Sep 2023 23:33 UTC
On 9/2/23 11:35 AM, Per Bothner wrote:
> On 9/1/23 23:08, John Cowan wrote:
>> In CL the function row-major-aref accepts an array and a single index
>> *n* and returns the *n*th element of the array in row-major order.
>> There is a corresponding function (setf row-major-aref) serving as the
>> corresponding mutator. This is equivalent to:
>>
>> (define (row-major-aref array n)
>> (vector-ref (array->vector array) n))
>>
>> but does not reify the results of `array->vector`. Is there some way
>> to do this with SRFI 231?
>
> In srfi-164 array->vector returns a view, not a copy.
> So your define works, and the same approach works for setting.
>
> It is unfortunate that array->vector is incompatible between srfi-231
> and srfi-164.
I think, e.g., Gambit would need to redefine vector-ref and vector-set!
to be more like Kawa's vector-ref and vector-set! for array->vector to
be allowed to return a view instead of a newly allocated vector.
Brad