mirror of
https://github.com/janet-lang/janet
synced 2025-01-11 08:00:27 +00:00
Add slice function to core.
Returns immutable slices.
This commit is contained in:
parent
339dea9390
commit
70ffe3b6bd
@ -564,7 +564,7 @@
|
|||||||
"(sort xs [, by])\n\nSort an array in-place. Uses quick-sort and is not a stable sort."
|
"(sort xs [, by])\n\nSort an array in-place. Uses quick-sort and is not a stable sort."
|
||||||
(do
|
(do
|
||||||
|
|
||||||
(defn partition
|
(defn part
|
||||||
[a lo hi by]
|
[a lo hi by]
|
||||||
(def pivot (get a hi))
|
(def pivot (get a hi))
|
||||||
(var i lo)
|
(var i lo)
|
||||||
@ -582,7 +582,7 @@
|
|||||||
(defn sort-help
|
(defn sort-help
|
||||||
[a lo hi by]
|
[a lo hi by]
|
||||||
(when (> hi lo)
|
(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 lo (- piv 1) by)
|
||||||
(sort-help a (+ piv 1) hi by))
|
(sort-help a (+ piv 1) hi by))
|
||||||
a)
|
a)
|
||||||
@ -1150,6 +1150,11 @@
|
|||||||
(if (not= i len) (array/push ret (slicer ind i)))
|
(if (not= i len) (array/push ret (slicer ind i)))
|
||||||
ret)
|
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
|
### IO Helpers
|
||||||
|
Loading…
Reference in New Issue
Block a user