From 4002b8988c799a904ef1f359d4267ef4ad80cba3 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Mon, 5 Dec 2022 14:19:12 +0200 Subject: Rename project to Milch --- stdlib/common.lisp | 69 ------------------------------------------ stdlib/common.milch | 69 ++++++++++++++++++++++++++++++++++++++++++ stdlib/maybe-with-unions.lisp | 42 ------------------------- stdlib/maybe-with-unions.milch | 42 +++++++++++++++++++++++++ stdlib/maybe.lisp | 51 ------------------------------- stdlib/maybe.milch | 51 +++++++++++++++++++++++++++++++ 6 files changed, 162 insertions(+), 162 deletions(-) delete mode 100644 stdlib/common.lisp create mode 100644 stdlib/common.milch delete mode 100644 stdlib/maybe-with-unions.lisp create mode 100644 stdlib/maybe-with-unions.milch delete mode 100644 stdlib/maybe.lisp create mode 100644 stdlib/maybe.milch (limited to 'stdlib') diff --git a/stdlib/common.lisp b/stdlib/common.lisp deleted file mode 100644 index 4d5b132..0000000 --- a/stdlib/common.lisp +++ /dev/null @@ -1,69 +0,0 @@ -(let! compose (\[f g] - (\[x] (f (g x))))) - -(let! id (\[a] a)) - -(let! mod (\[n k] - (- n (* k (/ n k))))) - -(let! not (\[b] - (match b - true false - false true))) - -(let! is-even (\[n] - (match (mod n 2) - 0 true - 1 false))) - -(let! is-odd (compose not is-even)) - -;; map :: (a -> b) -> [a] -> [b] -(let! map (\[f lst] - (match lst - [] - [] - otherwise - (prepend (f (head lst)) (map f (tail lst)))))) - -; (map (+ 1) [1 2 3]) - -;; foldr :: (a -> b -> b) -> b -> [a] -> b -(let! foldr (\[f accumulator lst] - (match lst - [] - accumulator - otherwise - (f (head lst) (foldr f accumulator (tail lst)))))) - -;; filter :: (a -> Bool) -> [a] -> [a] -(let! filter (\[pred lst] - (match lst - [] [] - otherwise (match (pred (head lst)) - true - (prepend (head lst) (filter pred (tail lst))) - false - (filter pred (tail lst)))))) - -(let! fibo (\[n] - (let! lazy fibo-1 (fibo (- n 1))) - (let! lazy fibo-2 (fibo (- n 2))) - (match n - 0 0 - 1 1 - _ (+ fibo-1 fibo-2)))) - -(let! reverse_ (\[v a] - (let! lazy x (head v)) - (let! lazy xs (tail v)) - (let! lazy xa (prepend x a)) - (match v - [] a - _ (reverse_ xs xa)))) - -(let! reverse (\[v] - (reverse_ v []))) - -(let! flow (\[fs] (foldr compose id (reverse fs)))) -(let! pipe (\[x fs] ((flow fs) x))) diff --git a/stdlib/common.milch b/stdlib/common.milch new file mode 100644 index 0000000..4d5b132 --- /dev/null +++ b/stdlib/common.milch @@ -0,0 +1,69 @@ +(let! compose (\[f g] + (\[x] (f (g x))))) + +(let! id (\[a] a)) + +(let! mod (\[n k] + (- n (* k (/ n k))))) + +(let! not (\[b] + (match b + true false + false true))) + +(let! is-even (\[n] + (match (mod n 2) + 0 true + 1 false))) + +(let! is-odd (compose not is-even)) + +;; map :: (a -> b) -> [a] -> [b] +(let! map (\[f lst] + (match lst + [] + [] + otherwise + (prepend (f (head lst)) (map f (tail lst)))))) + +; (map (+ 1) [1 2 3]) + +;; foldr :: (a -> b -> b) -> b -> [a] -> b +(let! foldr (\[f accumulator lst] + (match lst + [] + accumulator + otherwise + (f (head lst) (foldr f accumulator (tail lst)))))) + +;; filter :: (a -> Bool) -> [a] -> [a] +(let! filter (\[pred lst] + (match lst + [] [] + otherwise (match (pred (head lst)) + true + (prepend (head lst) (filter pred (tail lst))) + false + (filter pred (tail lst)))))) + +(let! fibo (\[n] + (let! lazy fibo-1 (fibo (- n 1))) + (let! lazy fibo-2 (fibo (- n 2))) + (match n + 0 0 + 1 1 + _ (+ fibo-1 fibo-2)))) + +(let! reverse_ (\[v a] + (let! lazy x (head v)) + (let! lazy xs (tail v)) + (let! lazy xa (prepend x a)) + (match v + [] a + _ (reverse_ xs xa)))) + +(let! reverse (\[v] + (reverse_ v []))) + +(let! flow (\[fs] (foldr compose id (reverse fs)))) +(let! pipe (\[x fs] ((flow fs) x))) diff --git a/stdlib/maybe-with-unions.lisp b/stdlib/maybe-with-unions.lisp deleted file mode 100644 index 53a5024..0000000 --- a/stdlib/maybe-with-unions.lisp +++ /dev/null @@ -1,42 +0,0 @@ -; LIB - -(union! Maybe - (just value) - (nothing)) - -(let! Maybe/map (\[f m] - (match (kind m) - "Maybe/Just" (Maybe/just (f (Maybe/Just/get-value m))) - "Maybe/Nothing" (Maybe/nothing)))) - -(let! Maybe/and-then (\[f m] - (match (kind m) - "Maybe/Just" (f (Maybe/Just/get-value m)) - "Maybe/Nothing" (Maybe/nothing)))) - -; TESTING - -;; (let! print-line! (\[s] -;; (print! (concat s "\n")))) - -;; (let! a (Maybe/just 10)) -;; (let! b (Maybe/nothing)) - -;; (Maybe/map (+ 5) a) -;; (Maybe/map (+ 5) b) - -;; (Maybe/and-then (\[n] (Maybe/just (+ n 5))) a) -;; (Maybe/and-then (\[n] (Maybe/just (+ n 5))) b) - -;; (let! m (Maybe/just 10)) -;; (match m -;; (Maybe/just _) -;; (print-line! (fmt "found just {0}!" [(Maybe/Just/get-value m)])) -;; (Maybe/nothing) -;; (print-line! "found nothing!")) - -;; (let! m (Maybe/just 10)) -;; (pipe m [ -;; (Maybe/map (+ 5)) -;; (Maybe/and-then (\[val] (Maybe/just (- val 3)))) -;; ]) diff --git a/stdlib/maybe-with-unions.milch b/stdlib/maybe-with-unions.milch new file mode 100644 index 0000000..53a5024 --- /dev/null +++ b/stdlib/maybe-with-unions.milch @@ -0,0 +1,42 @@ +; LIB + +(union! Maybe + (just value) + (nothing)) + +(let! Maybe/map (\[f m] + (match (kind m) + "Maybe/Just" (Maybe/just (f (Maybe/Just/get-value m))) + "Maybe/Nothing" (Maybe/nothing)))) + +(let! Maybe/and-then (\[f m] + (match (kind m) + "Maybe/Just" (f (Maybe/Just/get-value m)) + "Maybe/Nothing" (Maybe/nothing)))) + +; TESTING + +;; (let! print-line! (\[s] +;; (print! (concat s "\n")))) + +;; (let! a (Maybe/just 10)) +;; (let! b (Maybe/nothing)) + +;; (Maybe/map (+ 5) a) +;; (Maybe/map (+ 5) b) + +;; (Maybe/and-then (\[n] (Maybe/just (+ n 5))) a) +;; (Maybe/and-then (\[n] (Maybe/just (+ n 5))) b) + +;; (let! m (Maybe/just 10)) +;; (match m +;; (Maybe/just _) +;; (print-line! (fmt "found just {0}!" [(Maybe/Just/get-value m)])) +;; (Maybe/nothing) +;; (print-line! "found nothing!")) + +;; (let! m (Maybe/just 10)) +;; (pipe m [ +;; (Maybe/map (+ 5)) +;; (Maybe/and-then (\[val] (Maybe/just (- val 3)))) +;; ]) diff --git a/stdlib/maybe.lisp b/stdlib/maybe.lisp deleted file mode 100644 index 086b0dc..0000000 --- a/stdlib/maybe.lisp +++ /dev/null @@ -1,51 +0,0 @@ -; LIB - -(let! Maybe/just (\[a] - ["Maybe" "just" a])) -(let! Maybe/nothing (\[] - ["Maybe" "nothing"])) - -(let! Maybe/#at (\[n seq] - (match seq - [] - (fatal! "Maybe/#at out of bounds") - otherwise - (match n - 0 - (head seq) - otherwise - (Maybe/#at (- n 1) (tail seq)))))) - -(let! Maybe/unpack (Maybe/#at 2)) -(let! Maybe/kind (Maybe/#at 1)) - -(let! Maybe/map (\[f m] - (match (Maybe/kind m) - "just" (Maybe/just (f (Maybe/unpack m))) - "nothing" (Maybe/nothing)))) - -(let! Maybe/and-then (\[f m] - (match (Maybe/kind m) - "just" (f (Maybe/unpack m)) - "nothing" (Maybe/nothing)))) - -; TESTING - -;; (let! print-line! (\[s] -;; (print! (concat s "\n")))) - -;; (let! a (Maybe/just 10)) -;; (let! b (Maybe/nothing)) - -;; (Maybe/map (+ 5) a) -;; (Maybe/map (+ 5) b) - -;; (Maybe/and-then (\[n] (Maybe/just (+ n 5))) a) -;; (Maybe/and-then (\[n] (Maybe/just (+ n 5))) b) - -;; (let! m (Maybe/just 10)) -;; (match m -;; (Maybe/just _) -;; (print-line! (fmt "found just {0}!" [(Maybe/unpack m)])) -;; (Maybe/nothing) -;; (print-line! "found nothing!")) diff --git a/stdlib/maybe.milch b/stdlib/maybe.milch new file mode 100644 index 0000000..086b0dc --- /dev/null +++ b/stdlib/maybe.milch @@ -0,0 +1,51 @@ +; LIB + +(let! Maybe/just (\[a] + ["Maybe" "just" a])) +(let! Maybe/nothing (\[] + ["Maybe" "nothing"])) + +(let! Maybe/#at (\[n seq] + (match seq + [] + (fatal! "Maybe/#at out of bounds") + otherwise + (match n + 0 + (head seq) + otherwise + (Maybe/#at (- n 1) (tail seq)))))) + +(let! Maybe/unpack (Maybe/#at 2)) +(let! Maybe/kind (Maybe/#at 1)) + +(let! Maybe/map (\[f m] + (match (Maybe/kind m) + "just" (Maybe/just (f (Maybe/unpack m))) + "nothing" (Maybe/nothing)))) + +(let! Maybe/and-then (\[f m] + (match (Maybe/kind m) + "just" (f (Maybe/unpack m)) + "nothing" (Maybe/nothing)))) + +; TESTING + +;; (let! print-line! (\[s] +;; (print! (concat s "\n")))) + +;; (let! a (Maybe/just 10)) +;; (let! b (Maybe/nothing)) + +;; (Maybe/map (+ 5) a) +;; (Maybe/map (+ 5) b) + +;; (Maybe/and-then (\[n] (Maybe/just (+ n 5))) a) +;; (Maybe/and-then (\[n] (Maybe/just (+ n 5))) b) + +;; (let! m (Maybe/just 10)) +;; (match m +;; (Maybe/just _) +;; (print-line! (fmt "found just {0}!" [(Maybe/unpack m)])) +;; (Maybe/nothing) +;; (print-line! "found nothing!")) -- cgit v1.3