aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorJan Tuomi <jans.tuomi@gmail.com>2022-09-26 14:02:28 +0300
committerJan Tuomi <jans.tuomi@gmail.com>2022-12-05 14:21:53 +0200
commit2ea2c405746bfa79d3be478f4c8763dd7dd6ac5f (patch)
tree39be22d6a3b768e42813e2e5dde4a37a301aafb3 /examples
parent3f5b15b15fbca3dac18f3f5cb39b7826924ff175 (diff)
Add some concept docs
Diffstat (limited to 'examples')
-rw-r--r--examples/algebraic-types-concept.lisp19
-rw-r--r--examples/effects-concept.lisp19
2 files changed, 38 insertions, 0 deletions
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)