fix bug in at
This commit is contained in:
parent
716ecb01c5
commit
3d0b58e6ed
18
prelude.ld
18
prelude.ld
|
@ -5,7 +5,7 @@
|
||||||
fn and
|
fn and
|
||||||
fn append
|
fn append
|
||||||
fn apply_command
|
fn apply_command
|
||||||
fn assoc & ?
|
fn assoc
|
||||||
fn atan/2
|
fn atan/2
|
||||||
fn deg/rad
|
fn deg/rad
|
||||||
fn dict
|
fn dict
|
||||||
|
@ -15,6 +15,7 @@ fn get
|
||||||
fn join
|
fn join
|
||||||
fn mod
|
fn mod
|
||||||
fn neg?
|
fn neg?
|
||||||
|
fn print!
|
||||||
fn some?
|
fn some?
|
||||||
fn state/call
|
fn state/call
|
||||||
fn store!
|
fn store!
|
||||||
|
@ -190,8 +191,7 @@ fn list {
|
||||||
fn fold {
|
fn fold {
|
||||||
"Folds a list."
|
"Folds a list."
|
||||||
(f as :fn, xs as :list) -> fold (f, xs, f ())
|
(f as :fn, xs as :list) -> fold (f, xs, f ())
|
||||||
(f as :fn, xs as :list, root) -> {
|
(f as :fn, xs as :list, root) -> loop (root, first (xs), rest (xs)) with {
|
||||||
loop (root, first (xs), rest (xs)) with {
|
|
||||||
(prev, curr, []) -> f (prev, curr)
|
(prev, curr, []) -> f (prev, curr)
|
||||||
(prev, curr, remaining) -> recur (
|
(prev, curr, remaining) -> recur (
|
||||||
f (prev, curr)
|
f (prev, curr)
|
||||||
|
@ -199,7 +199,6 @@ fn fold {
|
||||||
rest (remaining)
|
rest (remaining)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
& TODO: optimize these with base :conj!
|
& TODO: optimize these with base :conj!
|
||||||
|
@ -375,12 +374,15 @@ fn strip {
|
||||||
fn words {
|
fn words {
|
||||||
"Takes a string and returns a list of the words in the string. Strips all whitespace."
|
"Takes a string and returns a list of the words in the string. Strips all whitespace."
|
||||||
(str as :string) -> {
|
(str as :string) -> {
|
||||||
|
print! (str)
|
||||||
let no_punct = strip (str)
|
let no_punct = strip (str)
|
||||||
|
print! (no_punct)
|
||||||
let strs = split (no_punct, " ")
|
let strs = split (no_punct, " ")
|
||||||
|
print! (strs)
|
||||||
fn worder (list, str) -> if empty? (str)
|
fn worder (list, str) -> if empty? (str)
|
||||||
then list
|
then do list > report!
|
||||||
else append (list, str)
|
else do append (list, str) > report!
|
||||||
fold (worder, strs, [])
|
do fold (worder, strs, []) > report!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -623,7 +625,7 @@ fn max {
|
||||||
& additional list operations now that we have comparitors
|
& additional list operations now that we have comparitors
|
||||||
fn at {
|
fn at {
|
||||||
"Returns the element at index n of a list or tuple, or the byte at index n of a string. Zero-indexed: the first element is at index 0. Returns nil if nothing is found in a list or tuple; returns an empty string if nothing is found in a string."
|
"Returns the element at index n of a list or tuple, or the byte at index n of a string. Zero-indexed: the first element is at index 0. Returns nil if nothing is found in a list or tuple; returns an empty string if nothing is found in a string."
|
||||||
(xs as :list, n as :number) -> base :nth (xs, n)
|
(xs as :list, n as :number) -> base :nth (n, xs)
|
||||||
(xs as :tuple, n as :number) -> base :nth (n, xs)
|
(xs as :tuple, n as :number) -> base :nth (n, xs)
|
||||||
(str as :string, n as :number) -> when {
|
(str as :string, n as :number) -> when {
|
||||||
neg? (n) -> ""
|
neg? (n) -> ""
|
||||||
|
|
|
@ -52,9 +52,7 @@
|
||||||
(comment
|
(comment
|
||||||
# (do
|
# (do
|
||||||
(def source `
|
(def source `
|
||||||
let myset = ${1, 2, 3, 3, 2}
|
fold (add, [1, 2, 3])
|
||||||
omit (2, myset)
|
|
||||||
myset
|
|
||||||
`)
|
`)
|
||||||
(def out (-> source
|
(def out (-> source
|
||||||
ludus
|
ludus
|
||||||
|
|
Loading…
Reference in New Issue
Block a user