1
0
mirror of https://github.com/janet-lang/janet synced 2024-06-16 10:19:55 +00:00

Add slice function to core.

Returns immutable slices.
This commit is contained in:
Calvin Rose 2019-09-24 19:44:07 -05:00
parent 339dea9390
commit 70ffe3b6bd

View File

@ -564,7 +564,7 @@
"(sort xs [, by])\n\nSort an array in-place. Uses quick-sort and is not a stable sort."
(do
(defn partition
(defn part
[a lo hi by]
(def pivot (get a hi))
(var i lo)
@ -582,7 +582,7 @@
(defn sort-help
[a lo hi by]
(when (> hi lo)
(def piv (partition a lo hi by))
(def piv (part a lo hi by))
(sort-help a lo (- piv 1) by)
(sort-help a (+ piv 1) hi by))
a)
@ -1150,6 +1150,11 @@
(if (not= i len) (array/push ret (slicer ind i)))
ret)
(defn slice
"Extract a sub-range of an indexed data strutrue or byte sequence."
[ind &opt start end]
((if (bytes? ind) string/slice tuple/slice) ind start end))
###
###
### IO Helpers