Add some new functions
This commit is contained in:
parent
84fd8779e3
commit
36d9ed8d69
|
@ -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)
|
||||||
then recur (b, cs)
|
(a, [b, ...cs]) -> if eq? (a, x)
|
||||||
else false
|
then recur (b, cs)
|
||||||
}
|
else false
|
||||||
|
}
|
||||||
|
else false
|
||||||
}
|
}
|
||||||
|
|
||||||
& TODO: add neq?
|
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)
|
||||||
|
else false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
& 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 ())
|
||||||
|
|
Loading…
Reference in New Issue
Block a user