Add some new functions

This commit is contained in:
Scott Richmond 2023-12-13 17:02:39 -05:00
parent 84fd8779e3
commit 36d9ed8d69

View File

@ -18,15 +18,36 @@ fn eq? {
"Returns true if all arguments have the same value." "Returns true if all arguments have the same value."
(x) -> true (x) -> true
(x, y) -> base :eq (x, y) (x, y) -> base :eq (x, y)
(x, y, ...zs) -> loop (y, zs) with { (x, y, ...zs) -> if eq? (x, y)
(a, [b]) -> base :eq (a, b) then loop (y, zs) with {
(a, [b, ...cs]) -> if base :eq (a, b) (a, []) -> eq? (a, x)
(a, [b, ...cs]) -> if eq? (a, x)
then recur (b, cs)
else false
}
else false
}
fn neq? {
"Returns true if none of the arguments have the same value."
(x) -> false
(x, y) -> not (eq? (x, y))
(x, y, ...zs) -> if eq? (x, y)
then false
else loop (y, zs) with {
(a, []) -> neq? (a, x)
(a, [b, ...cs]) -> if neq? (a, x)
then recur (b, cs) then recur (b, cs)
else false else false
} }
} }
& TODO: add neq? & tuples: not a lot you can do with them functionally
fn tuple? {
"Returns true if a value is a tuple."
(tuple as :tuple) -> true
(_) -> false
}
&&& functions: getting things done &&& functions: getting things done
fn fn? { fn fn? {
@ -137,6 +158,12 @@ fn set {
(xs as :tuple) -> base :into (${}, xs) (xs as :tuple) -> base :into (${}, xs)
} }
fn set? {
"Returns true if a value is a set."
(xs as :set) -> true
(_) -> false
}
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 ())