From 70ffe3b6bdbc9d543e6a75a45d5e71d454cc480e Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Tue, 24 Sep 2019 19:44:07 -0500 Subject: [PATCH] Add slice function to core. Returns immutable slices. --- src/boot/boot.janet | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/boot/boot.janet b/src/boot/boot.janet index f84c80f8..dad41f80 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -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