chickadee » generalized-arrays » array-slice

array-slice array start #!optional endprocedure

Slices an array starting from the start index to the (optional) end index. This procedure produces an array view (that satisfies array-view?) representing the sub-interval defined by [start end) in the array.

This procedure doesn't copy any elements of the array or modify the internal storage object shared with the original array, which makes it useful for designating smaller sub-sections of the array, for e.g. transduction or mutation.

 
(import generalized-arrays
        test)

(define a
  (make-array-from-storage vector-storage-class
                           (vector 3 3)
                           (vector 'a 'b 'c
                                   'd 'e 'f
                                   'g 'h 'i)))

;; Slice the array
;;
;; By default, `end` is the end of the array `a`
(define b (array-slice a #(1 1)))

(test-assert "Slice of array a"
  (array=? b (make-array-from-storage vector-storage-class
                                      (vector 2 2)
                                      (vector 'e 'f
                                              'h 'i)))