diff options
| author | Jan Tuomi <jans.tuomi@gmail.com> | 2022-09-26 23:28:51 +0300 |
|---|---|---|
| committer | Jan Tuomi <jans.tuomi@gmail.com> | 2022-12-05 14:21:53 +0200 |
| commit | 18c241ff7a53625c6f3c4e6f20ee8df5bb37ddf3 (patch) | |
| tree | 7b4df772e103b69b98316a2b902e7d34e6cdbfcb /examples | |
| parent | 5fd62d2d3e74e94a8b225f47af074b249ce7f932 (diff) | |
Add kinds of fixes and stuff
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/maybe.lisp | 41 |
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 |
