From 2ea2c405746bfa79d3be478f4c8763dd7dd6ac5f Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Mon, 26 Sep 2022 14:02:28 +0300 Subject: Add some concept docs --- examples/algebraic-types-concept.lisp | 19 +++++++++++++++++++ examples/effects-concept.lisp | 19 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 examples/algebraic-types-concept.lisp create mode 100644 examples/effects-concept.lisp (limited to 'examples') diff --git a/examples/algebraic-types-concept.lisp b/examples/algebraic-types-concept.lisp new file mode 100644 index 0000000..315a693 --- /dev/null +++ b/examples/algebraic-types-concept.lisp @@ -0,0 +1,19 @@ +(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 m (just 10)) +(match (kind m) + "just" (from-just m) + "nothing" "nothing") diff --git a/examples/effects-concept.lisp b/examples/effects-concept.lisp new file mode 100644 index 0000000..efca43e --- /dev/null +++ b/examples/effects-concept.lisp @@ -0,0 +1,19 @@ +; FUNCTIONS + +(let prompt-input (\[] + (let p "> ") + (do get-user-input "prompted" p))) + +; SIGNAL HANDLERS + +(on user-input (\[msg s] + (match msg + "prompted" (batch [ + (do print-line (fmt "You entered: %%" [s])) + (prompt-input)]) + (batch [ + (do fatal-error (fmt "error: unknown signal %%" [msg]))])))) + +;; ENTRYPOINT + +(prompt-input) -- cgit v1.3