aboutsummaryrefslogtreecommitdiffstats
path: root/examples/maybe.lisp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/maybe.lisp')
-rw-r--r--examples/maybe.lisp41
1 files changed, 31 insertions, 10 deletions
diff --git a/examples/maybe.lisp b/examples/maybe.lisp
index ce2cd03..c72e114 100644
--- a/examples/maybe.lisp
+++ b/examples/maybe.lisp
@@ -5,24 +5,45 @@
(let nothing (\[]
["maybe" "nothing"]))
-(let at (\[n seq]
+(let unsafe-at (\[n seq]
(match seq
- [] (nothing)
+ []
+ (error "unsafe-at out of bounds")
(match n
- 0 (head seq)
- (at (- n 1) (tail seq))))))
+ 0
+ (head seq)
+ (unsafe-at (- n 1) (tail seq))))))
-(let from-just (at 2))
-(let kind (at 1))
+(let unpack-just (unsafe-at 2))
+(let kind (unsafe-at 1))
(let map (\[f m]
(match (kind m)
- "just" (just (f (from-just m)))
- "nothing")))
+ "just" (just (f (unpack-just m)))
+ "nothing" (nothing))))
+
+(let and-then (\[f m]
+ (match (kind m)
+ "just" (f (unpack-just m))
+ "nothing" (nothing))))
; TESTING
+(let print-line! (\[s]
+ (print! (concat s "\n"))))
+
(let m (just 10))
(match (kind m)
- "just" (from-just m)
- "nothing" "nothing")
+ "just"
+ (print-line! (fmt "found just {0}!" [(unpack-just m)]))
+ "nothing"
+ (print-line! "found nothing!"))
+
+;; (export [
+;; just
+;; nothing
+;; unpack-just
+;; kind
+;; map
+;; and-then
+;; ]) \ No newline at end of file