fix slice

This commit is contained in:
Scott Richmond 2024-06-19 18:23:54 -04:00
parent 27b1bb4e50
commit 7bdaf291a0
3 changed files with 4 additions and 7 deletions

View File

@ -649,7 +649,7 @@ fn last {
fn butlast {
"Returns a list, omitting the last element."
(xs as :list) -> base :slice (xs, dec (count (xs)))
(xs as :list) -> base :slice (xs, 0, dec (count (xs)))
}
fn slice {
@ -659,10 +659,7 @@ fn slice {
gte? (start, end) -> []
gt? (end, count (xs)) -> slice (xs, start, count (xs))
neg? (start) -> slice (xs, 0, end)
true -> {
let slice = base :slice (xs, inc (start), inc (end))
base :into ([], slice)
}
true -> base :slice (xs, start, end)
}
(str as :string, end as :number) -> base :str_slice (str, 0, end)
(str as :string, start as :number, end as :number) -> base :str_slice (str, start, end)

View File

@ -281,7 +281,7 @@
"round" math/round
"show" show
"sin" math/sin
"slice" slice
"slice" array/slice
"split" string/split
"sqrt" math/sqrt
"store!" store!

View File

@ -52,7 +52,7 @@
(comment
# (do
(def source `
forward! (100)
butlast ([1, 2, 3])
`)
(def out (-> source
ludus