diff options
| author | Jan Tuomi <jans.tuomi@gmail.com> | 2022-12-05 14:19:12 +0200 |
|---|---|---|
| committer | Jan Tuomi <jans.tuomi@gmail.com> | 2022-12-05 14:21:53 +0200 |
| commit | 4002b8988c799a904ef1f359d4267ef4ad80cba3 (patch) | |
| tree | dbb67560f3a44c57df4b0e960861f60605ceb45f /examples/test.lisp | |
| parent | bba047ae945ae7d7899d6e2c1610923bcedb0442 (diff) | |
Rename project to Milch
Diffstat (limited to 'examples/test.lisp')
| -rw-r--r-- | examples/test.lisp | 81 |
1 files changed, 0 insertions, 81 deletions
diff --git a/examples/test.lisp b/examples/test.lisp deleted file mode 100644 index fd8c379..0000000 --- a/examples/test.lisp +++ /dev/null @@ -1,81 +0,0 @@ -(let! compose (\[f g] - (\[x] (f (g x))))) - -((compose (+ 1) (+ 2)) 3) - -(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)))))) - -(foldr + 0 [1 2 3]) - -;; 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)))))) - -(filter is-even [0 1 2 3 4 5]) - -(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)))) - -(fibo 10) - -(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 []))) - -(reverse [1 2 3]) - -(let! flow (\[fs] (foldr compose id (reverse fs)))) -(let! pipe (\[x fs] ((flow fs) x))) - -(pipe 10 [(+ 1) (+ 2)]) |
