Re: Lexicographical access to arrays
Bradley Lucier 10 Apr 2026 15:32 UTC
On 4/10/26 01:52, John Cowan wrote:
> It would be fine if this only worked for specialized arrays, where the
> elements*are* contiguous. In that case you don't have to do all the
> divisions and remainders: you look down at the storage-class body and
> work from that.
OK, I understand. Currently, e.g,
(apply array-fold-left op id arrays)
is implemented as
(if (and (fx<= (length arrays) 4)
(every (lambda (A)
(and (specialized-array? A) (%%array-packed? A)))
arrays))
(case (length arrays)
((1)
(let* ((domain (%%array-domain (car arrays)))
(lowers (%%interval-lower-bounds->list domain))
(number-of-elements (%%interval-volume domain))
(base_0 (apply (%%array-indexer (list-ref arrays 0))
lowers))
(getter_0
(storage-class-getter
(%%array-storage-class (list-ref arrays 0))))
(body_0 (%%array-body (list-ref arrays 0))))
(do ((elements-remaining
number-of-elements
(fx- elements-remaining 1))
(i_0 base_0 (fx+ i_0 1))
(result id (op result (getter_0 body_0 i_0))))
((eqv? elements-remaining 0) result))))
;;; cases for 2 to 4 arrays removed
)
;;; now the general case
(%%interval-fold-left
op
id
(%%array-domain (car arrays))
(map %%array-unsafe-getter arrays)))
Would adding an example like this under array-packed?