From 7a498e3a581f26b81fc9c2c9c7af8448a7f84f0f Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Tue, 4 Oct 2022 14:46:45 +0300 Subject: Rename and refactor --- examples/maybe.lisp | 51 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 21 deletions(-) (limited to 'examples/maybe.lisp') diff --git a/examples/maybe.lisp b/examples/maybe.lisp index fe0b418..dab7bf8 100644 --- a/examples/maybe.lisp +++ b/examples/maybe.lisp @@ -1,14 +1,14 @@ ; LIB -(let just (\[a] +(let! just (\[a] ["maybe" "just" a])) -(let nothing (\[] +(let! nothing (\[] ["maybe" "nothing"])) -(let unsafe-at (\[n seq] +(let! unsafe-at (\[n seq] (match seq [] - (fatal "unsafe-at out of bounds") + (fatal! "unsafe-at out of bounds") otherwise (match n 0 @@ -16,36 +16,45 @@ otherwise (unsafe-at (- n 1) (tail seq)))))) -(let unpack-just (unsafe-at 2)) -(let kind (unsafe-at 1)) +(let! unpack-just (unsafe-at 2)) +(let! kind (unsafe-at 1)) -(let map (\[f m] +(let! map (\[f m] (match (kind m) "just" (just (f (unpack-just m))) "nothing" (nothing)))) -(let and-then (\[f m] +(let! and-then (\[f m] (match (kind m) "just" (f (unpack-just m)) "nothing" (nothing)))) ; TESTING -(let print-line! (\[s] +(let! print-line! (\[s] (print! (concat s "\n")))) -(let m (just 10)) -(match (kind m) - "just" +(let! a (just 10)) +(let! b (nothing)) + +(map (+ 5) a) +(map (+ 5) b) + +(and-then (\[n] (just (+ n 5))) a) +(and-then (\[n] (just (+ n 5))) b) + +(let! m (just 10)) +(match m + (just _) (print-line! (fmt "found just {0}!" [(unpack-just m)])) - "nothing" + (nothing) (print-line! "found nothing!")) -(let exports [ - just - nothing - unpack-just - kind - map - and-then -]) +;; (let! exports [ +;; just +;; nothing +;; unpack-just +;; kind +;; map +;; and-then +;; ]) -- cgit v1.3