From 36d9ed8d697d81e0e21d21c001dd7c66975dab71 Mon Sep 17 00:00:00 2001 From: Scott Richmond Date: Wed, 13 Dec 2023 17:02:39 -0500 Subject: [PATCH] Add some new functions --- src/ludus/prelude.ld | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/src/ludus/prelude.ld b/src/ludus/prelude.ld index fcbacc7..8100144 100644 --- a/src/ludus/prelude.ld +++ b/src/ludus/prelude.ld @@ -18,15 +18,36 @@ fn eq? { "Returns true if all arguments have the same value." (x) -> true (x, y) -> base :eq (x, y) - (x, y, ...zs) -> loop (y, zs) with { - (a, [b]) -> base :eq (a, b) - (a, [b, ...cs]) -> if base :eq (a, b) - then recur (b, cs) - else false - } + (x, y, ...zs) -> if eq? (x, y) + then loop (y, zs) with { + (a, []) -> eq? (a, x) + (a, [b, ...cs]) -> if eq? (a, x) + 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 fn fn? { @@ -137,6 +158,12 @@ fn set { (xs as :tuple) -> base :into (${}, xs) } +fn set? { + "Returns true if a value is a set." + (xs as :set) -> true + (_) -> false +} + fn fold { "Folds a list." (f as :fn, xs as :list) -> fold (f, xs, f ())