Re: array-assign! can have different effects with specialized and generalized arrays.
Bradley Lucier 16 Nov 2026 20:08 UTC
On 11/15/26 08:36, Peter McGoron wrote:
> Maybe have (specialized-array-assign! dst src) use the unspecified order
> of the array copier (which require *dst* and *src* to be specialized
> arrays), and (array-assign! dst src) can be strictly interleaved? I am
> unsure if this covers all of the cases.
Perhaps this is close to the right solution.
The issue arose in my mind when I considered adding a copier (with
memmove semantics) to u1-storage-class in the sample implementation.
That's when I realized that array-assign! behaves differently for
specialized arrays with and without storage-class-copiers in the sample
implementation. This code:
(import (srfi 231))
(define zeros-and-ones (map (lambda (n) (modulo n 2)) (iota 10)))
(for-each (lambda (storage-class name)
(let* ((A (list*->array 1 zeros-and-ones storage-class))
(A-front (array-extract A (make-interval '#(9))))
(A-back (array-extract A (make-interval '#(1)
'#(10)))))
(for-each display (list "\n"
name
"-array A before assignment\n"))
(pretty-print (array->list* A))
(array-assign! A-back (array-translate A-front '#(1)))
(for-each display (list "\n"
name
"-array A after assignment\n"))
(pretty-print (array->list* A))))
(list u1-storage-class u16-storage-class)
'("u1" "u16"))
displays
u1-array A before assignment
(0 1 0 1 0 1 0 1 0 1)
u1-array A after assignment
(0 0 0 0 0 0 0 0 0 0)
u16-array A before assignment
(0 1 0 1 0 1 0 1 0 1)
u16-array A after assignment
(0 0 1 0 1 0 1 0 1 0)
If I add a copier to u1-storage-class, the two results will be the same.
Are we *really* going to say that if the source and destination arrays
are packed specialized arrays with the same storage class then the
effects of array-assign! are going to depend on whether the storage
class has a copier?
Or should we give copiers have the semantics of memcpy instead of
memmove? This would go against the specification of vector-copy! in
SRFI 133:
(vector-copy! to at from [start [end]]) -> unspecified
[R7RS-small] Copies the elements of vector from between start and
end to vector to, starting at at. The order in which elements are copied
is unspecified, except that if the source and destination overlap,
copying takes place as if the source is first copied into a temporary
vector and then into the destination. This can be achieved without
allocating storage by making sure to copy in the correct direction in
such circumstances.
Brad