Array slices (subarrays)
Add support creating a slice (subarray) of an array. This might be added to
define-array-accessors or a new macro that generates new procedures. There might be two possible procedures to generate:
(SLICE array start-index #!optional end-index)
(SLICE* array byte-offset length)
Both would return a new array armor that is a child of the original array armor, and wraps a portion of the original data, so changing the child affects the parent, and vice versa.
(REF child 0) would correspond to
(REF array start-index).
SLICE can be implemented in terms of
SLICE* like so:
(define (SLICE array start-index #!optional end-index) (let ((byte-offset (* start-index (foreign-type-size STRUCT_NAME))) (length (- (or end-index (LENGTH array)) start-index))) (SLICE* array byte-offset length)))
The reason for providing both procedures is that
SLICE* could be used to support multidimensional arrays which have padding bytes at the end of a row, such as pixel data in an image.
Use cases for this feature:
- Iterating or mapping over part of the original array
- Exposing a limited subview of the original array