One-dimensional array slicing

Uses
- One-dimensional array indexation
- Integers
- Integer grids

Slicing refers to extracting a sub-array corresponding to an interval of indices, as defined in Integer grids.

The special value
∎ : ℕ.nz
stands for the last index of the array. The interval spanning all array elements would thus be written
1

A slice is extracted by using an interval or grid as a subscript:
s:𝕊, (Array1D(s))[ℕ.nz⧺ℕ.nz⧺ℕ.nz] : Array1D(s)

For array terms, the slice is computed in Pharo code:
s_:𝕊, A:Array1D(s_), i:ℕ.nz, j:ℕ.nz, A[i j] ⇒ Pharo:"A ensureArrayTerm. i ensureNumber. j ensureNumber. A slice: i to: j by: 1"
s_:𝕊, A:Array1D(s_), i:ℕ.nz, j:ℕ.nz, k:ℕ.nz, A[i k j] ⇒ Pharo:"A ensureArrayTerm. i ensureNumber. j ensureNumber. k ensureNumber. A slice: i to: j by: k"

For the special case of a slice to the end:
s_:𝕊, A:Array1D(s_), i:ℕ.nz, A[i ∎] ⇒ Pharo:"A ensureArrayTerm. i ensureNumber. A sliceToEndFrom: i by: 1"
s_:𝕊, A:Array1D(s_), i:ℕ.nz, k:ℕ.nz, A[i k ∎] ⇒ Pharo:"A ensureArrayTerm. i ensureNumber. k ensureNumber. A sliceToEndFrom: i by: k"

Example

For a literal array:
{[1, 4, 9, 16, 25, 36]}[2 3] ⇒ {[4, 9]}
{[1, 4, 9, 16, 25, 36]}[3 ∎] ⇒ {[9, 16, 25, 36]}
{[1, 4, 9, 16, 25, 36]}[1 2 5] ⇒ {[1, 9, 25]}
{[1, 4, 9, 16, 25, 36]}[2 2 ∎] ⇒ {[4, 16, 36]}