From f8578936553468785ff1c70fb7f4b0efebfbf55d Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Mon, 26 Sep 2022 16:29:32 +0300 Subject: Add maybe concept --- examples/maybe.lisp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 examples/maybe.lisp (limited to 'examples/maybe.lisp') diff --git a/examples/maybe.lisp b/examples/maybe.lisp new file mode 100644 index 0000000..ce2cd03 --- /dev/null +++ b/examples/maybe.lisp @@ -0,0 +1,28 @@ +; LIB + +(let just (\[a] + ["maybe" "just" a])) +(let nothing (\[] + ["maybe" "nothing"])) + +(let at (\[n seq] + (match seq + [] (nothing) + (match n + 0 (head seq) + (at (- n 1) (tail seq)))))) + +(let from-just (at 2)) +(let kind (at 1)) + +(let map (\[f m] + (match (kind m) + "just" (just (f (from-just m))) + "nothing"))) + +; TESTING + +(let m (just 10)) +(match (kind m) + "just" (from-just m) + "nothing" "nothing") -- cgit v1.3