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 --- examples/effects-concept.lisp | 18 ---------- examples/effects-concept.milch | 18 ++++++++++ examples/import.lisp | 2 -- examples/import.milch | 2 ++ examples/impure-concept.lisp | 12 ------- examples/impure-concept.milch | 12 +++++++ examples/purity-test.lisp | 20 ----------- examples/purity-test.milch | 25 +++++++++++++ examples/records-concept.lisp | 51 -------------------------- examples/records-concept.milch | 51 ++++++++++++++++++++++++++ examples/test.lisp | 81 ------------------------------------------ examples/test.milch | 81 ++++++++++++++++++++++++++++++++++++++++++ examples/types-concept.lisp | 34 ------------------ examples/types-concept.milch | 34 ++++++++++++++++++ 14 files changed, 223 insertions(+), 218 deletions(-) delete mode 100644 examples/effects-concept.lisp create mode 100644 examples/effects-concept.milch delete mode 100644 examples/import.lisp create mode 100644 examples/import.milch delete mode 100644 examples/impure-concept.lisp create mode 100644 examples/impure-concept.milch delete mode 100644 examples/purity-test.lisp create mode 100644 examples/purity-test.milch delete mode 100644 examples/records-concept.lisp create mode 100644 examples/records-concept.milch delete mode 100644 examples/test.lisp create mode 100644 examples/test.milch delete mode 100644 examples/types-concept.lisp create mode 100644 examples/types-concept.milch (limited to 'examples') diff --git a/examples/effects-concept.lisp b/examples/effects-concept.lisp deleted file mode 100644 index 5ea90d7..0000000 --- a/examples/effects-concept.lisp +++ /dev/null @@ -1,18 +0,0 @@ -; FUNCTIONS - -(let! prompt-input (\[] - (let! p "> ") - (do get-user-input "prompted" p))) - -; SIGNAL HANDLERS - -(on user-input (\[msg s] - (match msg - "prompted" (batch [ - (do print-line (fmt "You entered: %%" [s])) - (prompt-input)]) - (do fatal-error (fmt "error: unknown signal %%" [msg]))))) - -; ENTRYPOINT - -(prompt-input) diff --git a/examples/effects-concept.milch b/examples/effects-concept.milch new file mode 100644 index 0000000..5ea90d7 --- /dev/null +++ b/examples/effects-concept.milch @@ -0,0 +1,18 @@ +; FUNCTIONS + +(let! prompt-input (\[] + (let! p "> ") + (do get-user-input "prompted" p))) + +; SIGNAL HANDLERS + +(on user-input (\[msg s] + (match msg + "prompted" (batch [ + (do print-line (fmt "You entered: %%" [s])) + (prompt-input)]) + (do fatal-error (fmt "error: unknown signal %%" [msg]))))) + +; ENTRYPOINT + +(prompt-input) diff --git a/examples/import.lisp b/examples/import.lisp deleted file mode 100644 index 1a2f6f1..0000000 --- a/examples/import.lisp +++ /dev/null @@ -1,2 +0,0 @@ -(import! "stdlib/common.lisp") -(import! M "stdlib/maybe.lisp") diff --git a/examples/import.milch b/examples/import.milch new file mode 100644 index 0000000..e839ef0 --- /dev/null +++ b/examples/import.milch @@ -0,0 +1,2 @@ +(import! "stdlib/common.milch") +(import! M "stdlib/maybe.milch") diff --git a/examples/impure-concept.lisp b/examples/impure-concept.lisp deleted file mode 100644 index 893b29e..0000000 --- a/examples/impure-concept.lisp +++ /dev/null @@ -1,12 +0,0 @@ -; What color is your function? -; Impure functions are functions that can call both pure and impure functions. -; Pure functions can only call pure functions. -; Impure function names end in an exclamation mark (!) by convention. -; The top-level context is impure but has special rules -; related to `import!`, `let!`, and other builtins. - -; pure function -(let! f (\[x] x)) - -; impure function -(let! g! (\![x] (print! x))) diff --git a/examples/impure-concept.milch b/examples/impure-concept.milch new file mode 100644 index 0000000..893b29e --- /dev/null +++ b/examples/impure-concept.milch @@ -0,0 +1,12 @@ +; What color is your function? +; Impure functions are functions that can call both pure and impure functions. +; Pure functions can only call pure functions. +; Impure function names end in an exclamation mark (!) by convention. +; The top-level context is impure but has special rules +; related to `import!`, `let!`, and other builtins. + +; pure function +(let! f (\[x] x)) + +; impure function +(let! g! (\![x] (print! x))) diff --git a/examples/purity-test.lisp b/examples/purity-test.lisp deleted file mode 100644 index 31e82d3..0000000 --- a/examples/purity-test.lisp +++ /dev/null @@ -1,20 +0,0 @@ -(let! f (\[x] x)) -(f 10) - -(let! g! (\![x] (print! x))) -(g! "foo") - -(let! h (\[x] (g! x))) -(h "bar") - -(let! main! (\![] - (print! (fmt "{0}\n" ["main"])) - )) - -(main!) - -(let! pure-main (\[] - (print! (fmt "{0}\n" ["pure-main"])) - )) - -(pure-main) diff --git a/examples/purity-test.milch b/examples/purity-test.milch new file mode 100644 index 0000000..6e8faea --- /dev/null +++ b/examples/purity-test.milch @@ -0,0 +1,25 @@ +; utils + +(let! println! (\![x] + (print! (fmt "{0}\n" [x])))) + +; pure vs. impure demo + +; this is a pure function +(let! f (\[x] x)) + +(f 10) ; works + +; this is an impure function +(let! g! (\![x] (println! x))) + +(g! "foo") ; works + +; this is a pure function that tries to call an impure function +(let! h (\[x] (g! x))) + +(h "bar") +; error: cannot call impure function in pure context +; when calling function g! at examples/purity-test.milch:19:15 +; in a function definition at examples/purity-test.milch:19:12 +; when calling function h at examples/purity-test.milch:21:1 diff --git a/examples/records-concept.lisp b/examples/records-concept.lisp deleted file mode 100644 index 420fa9f..0000000 --- a/examples/records-concept.lisp +++ /dev/null @@ -1,51 +0,0 @@ -; Records are named tuples with an identifier. `record!` is a builtin function -; that generates functions for creating, reading and modifying a record. -; In type system terms, records are intersections. - -; `record!` can only be called in the top-level context. - -(record! Ns/User - name - phone-number) - -; Generates the following functions: - -(let! user - (Ns/User/create "John" "010-123-456")) - ; user ~> (Ns/User name:"John" phone-number:"010-123-456") - -(Ns/User/get-name user) ; => "John" -(Ns/User/get-phone-number user) ; => "010-123-456" - -(Ns/User/set-name "Rick" user) - ; => (Ns/User name:"Rick" phone-number:"010-123-456") -(Ns/User/set-phone-number unit user) - ; => (Ns/User name:"Rick" phone-number:) - - - - -; Unions are unions of records with an identifier. `union!` is a builtin function -; that generates functions for manipulating the records in the union. - -; `union!` can only be called in the top-level context. - -(union! Ns/Maybe - (just value) - (nothing)) - -; Generates the following functions: - -(let! m1 (Ns/Maybe/just 10)) ; m1 ~> (Ns/Maybe/Just value:10) -(let! m2 (Ns/Maybe/nothing)) ; m2 ~> (Ns/Maybe/Nothing) - -(Ns/Maybe/Just/get-value m1) ; => 10 - - - - -; The builtin function `kind` returns the identifier as a string for any record value - -(kind m1) ; => "Ns/Maybe/Just" -(kind m2) ; => "Ns/Maybe/Nothing" -(kind user) ; => "Ns/User" diff --git a/examples/records-concept.milch b/examples/records-concept.milch new file mode 100644 index 0000000..420fa9f --- /dev/null +++ b/examples/records-concept.milch @@ -0,0 +1,51 @@ +; Records are named tuples with an identifier. `record!` is a builtin function +; that generates functions for creating, reading and modifying a record. +; In type system terms, records are intersections. + +; `record!` can only be called in the top-level context. + +(record! Ns/User + name + phone-number) + +; Generates the following functions: + +(let! user + (Ns/User/create "John" "010-123-456")) + ; user ~> (Ns/User name:"John" phone-number:"010-123-456") + +(Ns/User/get-name user) ; => "John" +(Ns/User/get-phone-number user) ; => "010-123-456" + +(Ns/User/set-name "Rick" user) + ; => (Ns/User name:"Rick" phone-number:"010-123-456") +(Ns/User/set-phone-number unit user) + ; => (Ns/User name:"Rick" phone-number:) + + + + +; Unions are unions of records with an identifier. `union!` is a builtin function +; that generates functions for manipulating the records in the union. + +; `union!` can only be called in the top-level context. + +(union! Ns/Maybe + (just value) + (nothing)) + +; Generates the following functions: + +(let! m1 (Ns/Maybe/just 10)) ; m1 ~> (Ns/Maybe/Just value:10) +(let! m2 (Ns/Maybe/nothing)) ; m2 ~> (Ns/Maybe/Nothing) + +(Ns/Maybe/Just/get-value m1) ; => 10 + + + + +; The builtin function `kind` returns the identifier as a string for any record value + +(kind m1) ; => "Ns/Maybe/Just" +(kind m2) ; => "Ns/Maybe/Nothing" +(kind user) ; => "Ns/User" 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)]) diff --git a/examples/test.milch b/examples/test.milch new file mode 100644 index 0000000..fd8c379 --- /dev/null +++ b/examples/test.milch @@ -0,0 +1,81 @@ +(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)]) diff --git a/examples/types-concept.lisp b/examples/types-concept.lisp deleted file mode 100644 index 8359c6b..0000000 --- a/examples/types-concept.lisp +++ /dev/null @@ -1,34 +0,0 @@ -; lowercase types: polymorphic -; everything else: monomorphic - -(type compose (\[ - (\[b] c) ; f - (\[a] b)] ; g - (\[a] c))) -(let! - compose (\[f g] (\[x] (f (g x))))) - -((compose (+ 1) (+ 2)) 3) - -(type id (\[a] a)) -(let! id (\[a] a)) - -(type mod (\[Int Int] Int)) -(let! mod (\[n k] - (- n (* k (/ n k))))) - -(type not (\[Bool] Bool)) -(let! not (\[b] - (match b - true false - false true))) - -(type is-even (\[Int] Bool)) -(let! is-even (\[n] - (match (mod n 2) - 0 true - 1 false))) - -; match cannot be type annotated because its variadic -; but the match above is inferred as this: -(type match (\[a a b a b] b)) diff --git a/examples/types-concept.milch b/examples/types-concept.milch new file mode 100644 index 0000000..8359c6b --- /dev/null +++ b/examples/types-concept.milch @@ -0,0 +1,34 @@ +; lowercase types: polymorphic +; everything else: monomorphic + +(type compose (\[ + (\[b] c) ; f + (\[a] b)] ; g + (\[a] c))) +(let! + compose (\[f g] (\[x] (f (g x))))) + +((compose (+ 1) (+ 2)) 3) + +(type id (\[a] a)) +(let! id (\[a] a)) + +(type mod (\[Int Int] Int)) +(let! mod (\[n k] + (- n (* k (/ n k))))) + +(type not (\[Bool] Bool)) +(let! not (\[b] + (match b + true false + false true))) + +(type is-even (\[Int] Bool)) +(let! is-even (\[n] + (match (mod n 2) + 0 true + 1 false))) + +; match cannot be type annotated because its variadic +; but the match above is inferred as this: +(type match (\[a a b a b] b)) -- cgit v1.3