JanetDocsI'm feeling luckyGithub sign in

slice



    cfunction

    (slice x &opt start end)
    
    Extract a sub-range of an indexed data structure or byte sequence.


1 exampleSign in to add an example
Loading...
(slice [:a :b :c :d])  # => (:a :b :c :d)

(slice [:a :b :c :d] 0)  # => (:a :b :c :d)
(slice [:a :b :c :d] 1)  # => (:b :c :d)
(slice [:a :b :c :d] 3)  # => (:d)
(slice [:a :b :c :d] 4)  # => ()
(slice [:a :b :c :d] 5)  # error: index out of range

(slice [:a :b :c :d] -1)  # => ()
(slice [:a :b :c :d] -2)  # => (:d)
(slice [:a :b :c :d] -4)  # => (:b :c :d)
(slice [:a :b :c :d] -5)  # => (:a :b :c :d)
(slice [:a :b :c :d] -6)  # error: index out of range

(slice [:a :b :c :d] 0 0)  # => ()
(slice [:a :b :c :d] 0 1)  # => (:a)
(slice [:a :b :c :d] 0 4)  # => (:a :b :c :d)

(slice [:a :b :c :d] -1 -1)  # => ()
(slice [:a :b :c :d] -2 -1)  # => (:d)
(slice [:a :b :c :d] -5 -1)  # => (:a :b :c :d)

(slice [:a :b :c :d] 1 0)  # => ()
(slice [:a :b :c :d] 4 0)  # => ()
(slice [:a :b :c :d] -1 -2)  # => ()
(slice [:a :b :c :d] -1 -5)  # => ()
cellularmitosis