array-assign! can have different effects with specialized and generalized arrays.
Bradley Lucier 14 Nov 2026 22:55 UTC
In the sample implementation array-assign! can have different effects
with overlapping arrays depending on whether or not vector-copy! (or
friends) are used to assign elements of the source array to the
destination array.
For example, if you have
(import (srfi 231))
(let* ((A (list*->array 1 (iota 10)))
(A-front (array-extract A (make-interval '#(9))))
(A-back (array-extract A (make-interval '#(1) '#(10)))))
(array-assign! A-back (array-translate A-front '#(1)))
(display "\narray-assign! with specialized array source\n")
(pretty-print (array->list* A)))
(let* ((A (list*->array 1 (iota 10)))
(A-front (array-extract A (make-interval '#(9))))
(A-back (array-extract A (make-interval '#(1) '#(10))))
(generic-A-front (make-array (array-domain A-front)
(array-getter A-front))))
(array-assign! A-back (array-translate generic-A-front '#(1)))
(display "\narray-assign! with generalized array source\n")
(pretty-print (array->list* A)))
the result is
heine:~/lang/scheme/srfi-231/srfi-231-temp> gsi test-assign.scm
array-assign! with specialized array source
(0 0 1 2 3 4 5 6 7 8)
array-assign! with generalized array source
(0 0 0 0 0 0 0 0 0 0)
This is because assignments of packed specialized arrays with
generic-storage-class are effected with vector-copy!, which Does The
Right Thing (TM) by copying overlapping regions from back to front if
necessary, as in the first assignation.
In the second assignation, after we make a generalized array of A-front,
array-assign! interleaves computing each source element with assigning
it to its place in the destination array in lexicographical order.
One might want the interleaved computation and assignment of array
elements, as in
(let* ((A (list*->array 1 (make-list 10 1)))
(A-front (array-extract A (make-interval '#(9))))
(A-back (array-extract A (make-interval '#(1) '#(10)))))
(display "\narray before computation\n")
(pretty-print (array->list* A))
(display "\narray after computation\n")
(array-assign! A-back (array-map + (array-translate A-front '#(1))
A-back))
(pretty-print (array->list* A)))
which prints
array before computation
(1 1 1 1 1 1 1 1 1 1)
array after computation
(1 2 3 4 5 6 7 8 9 10)
Should we make the description of array-assign! more precise?
I'm not even sure what the correct semantics should be.
Brad