cfunction
src/core/array.c on line 229, column 1
(array/slice arrtup &opt start end)
Takes a slice of array or tuple from `start` to `end`. The range is
half open, [start, end). Indexes can also be negative, indicating
indexing from the end of the array. By default, `start` is 0 and
`end` is the length of the array. Note that if the range is
negative, it is taken as (start, end] to allow a full negative
slice range. Returns a new array.
(def a @[1 2 3 ])
(def b (array/slice a ))
#=> good way to clone array, a and b are different arrays
(array/slice [1 2 3 ])
#=> @[1 2 3]
# good way to convert tuple to array
(array/slice @[1 2 3 ] 0 0 ) # => @[]
(array/slice @[1 2 3 ] 0 1 ) # => @[1]
(array/slice @[1 2 3 ] 0 2 ) # => @[1 2]
(array/slice @[1 2 3 ] 0 3 ) # => @[1 2 3]
(array/slice @[1 2 3 ] 0 4 ) # error: index out of range
(array/slice @[1 2 3 ] 1 1 ) # => @[]
(array/slice @[1 2 3 ] 1 2 ) # => @[2]
(array/slice @[1 2 3 ] 0 -1 ) # => @[1 2 3]
(array/slice @[1 2 3 ] 0 -2 ) # => @[1 2]
(array/slice @[1 2 3 ] 0 -3 ) # => @[1]
(array/slice @[1 2 3 ] 0 -4 ) # => @[]
(array/slice @[1 2 3 ] 0 -5 ) # error: index out of range