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 | |
| parent | bba047ae945ae7d7899d6e2c1610923bcedb0442 (diff) | |
Rename project to Milch
| -rw-r--r-- | README.md | 15 | ||||
| -rw-r--r-- | examples/effects-concept.milch (renamed from examples/effects-concept.lisp) | 0 | ||||
| -rw-r--r-- | examples/import.lisp | 2 | ||||
| -rw-r--r-- | examples/import.milch | 2 | ||||
| -rw-r--r-- | examples/impure-concept.milch (renamed from examples/impure-concept.lisp) | 0 | ||||
| -rw-r--r-- | examples/purity-test.lisp | 20 | ||||
| -rw-r--r-- | examples/purity-test.milch | 25 | ||||
| -rw-r--r-- | examples/records-concept.milch (renamed from examples/records-concept.lisp) | 0 | ||||
| -rw-r--r-- | examples/test.milch (renamed from examples/test.lisp) | 0 | ||||
| -rw-r--r-- | examples/types-concept.milch (renamed from examples/types-concept.lisp) | 0 | ||||
| -rw-r--r-- | src/Utils.hs | 14 | ||||
| -rw-r--r-- | stdlib/common.milch (renamed from stdlib/common.lisp) | 0 | ||||
| -rw-r--r-- | stdlib/maybe-with-unions.milch (renamed from stdlib/maybe-with-unions.lisp) | 0 | ||||
| -rw-r--r-- | stdlib/maybe.milch (renamed from stdlib/maybe.lisp) | 0 | ||||
| -rw-r--r-- | todo.md | 4 |
15 files changed, 50 insertions, 32 deletions
@@ -1,4 +1,10 @@ -# lang +# MILCH: [M]y functional language [I]nspired by [L]isp, [C]lojure, and [H]askell + +## Summary + +`MILCH` (or `Milch`, or `milch`) is a interpreted, dynamically typed functional programming language that has some Lisp-inspired syntax and Haskell-inspired semantics. Milch is german for 🥛. + +I'm developing this language by myself as a hobby, and the spec is going to change all the time. Some features documented here might not yet be implemented. Check out the language spec [spec.md](spec.md) @@ -6,6 +12,13 @@ Check out the language spec Check out the TODO [todo.md](todo.md) +## Usage + +Install a Haskell toolchain with Stack and GHC. Run + + stack run -- -h + +to see the help text. ## Author diff --git a/examples/effects-concept.lisp b/examples/effects-concept.milch index 5ea90d7..5ea90d7 100644 --- a/examples/effects-concept.lisp +++ b/examples/effects-concept.milch 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.milch index 893b29e..893b29e 100644 --- a/examples/impure-concept.lisp +++ b/examples/impure-concept.milch 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.milch index 420fa9f..420fa9f 100644 --- a/examples/records-concept.lisp +++ b/examples/records-concept.milch diff --git a/examples/test.lisp b/examples/test.milch index fd8c379..fd8c379 100644 --- a/examples/test.lisp +++ b/examples/test.milch diff --git a/examples/types-concept.lisp b/examples/types-concept.milch index 8359c6b..8359c6b 100644 --- a/examples/types-concept.lisp +++ b/examples/types-concept.milch diff --git a/src/Utils.hs b/src/Utils.hs index 0cc17bd..b68de18 100644 --- a/src/Utils.hs +++ b/src/Utils.hs @@ -39,7 +39,7 @@ data LState = LState { stateConfig :: Config, stateEnv :: Env, stateDepth :: Int, - statePure :: LIsPure + statePure :: Purity } type LineNo = Int @@ -92,12 +92,12 @@ getDepth = do s <- get return $ stateDepth s -getPurity :: LContext LIsPure +getPurity :: LContext Purity getPurity = do s <- get return $ statePure s -isAllowedPurity :: LIsPure -> LContext Bool +isAllowedPurity :: Purity -> LContext Bool isAllowedPurity purity = do s <- get let currentPurity = statePure s @@ -105,11 +105,11 @@ isAllowedPurity purity = do False -> True -- if currently in impure context (false), all calls are ok True -> purity == True -- but if in pure context (true), only pure calls are ok -updatePurity :: LIsPure -> LContext () +updatePurity :: Purity -> LContext () updatePurity purity = do modify (\s -> s { statePure = purity }) -checkPurity :: LIsPure -> LContext () +checkPurity :: Purity -> LContext () checkPurity purity = do purityOk <- isAllowedPurity purity when (not purityOk) $ throwL "" $ "cannot call impure function in pure context" @@ -127,7 +127,7 @@ instance (Eq Token) where instance (Show Token) where show token = show $ tokenContent token -type LIsPure = Bool +type Purity = Bool type LFunction = AST -> LContext AST data ASTNode @@ -139,7 +139,7 @@ data ASTNode | ASTVector [AST] | ASTFunctionCall [AST] | ASTHashMap (M.Map AST AST) - | ASTFunction LIsPure LFunction + | ASTFunction Purity LFunction | ASTUnit | ASTHole diff --git a/stdlib/common.lisp b/stdlib/common.milch index 4d5b132..4d5b132 100644 --- a/stdlib/common.lisp +++ b/stdlib/common.milch diff --git a/stdlib/maybe-with-unions.lisp b/stdlib/maybe-with-unions.milch index 53a5024..53a5024 100644 --- a/stdlib/maybe-with-unions.lisp +++ b/stdlib/maybe-with-unions.milch diff --git a/stdlib/maybe.lisp b/stdlib/maybe.milch index 086b0dc..086b0dc 100644 --- a/stdlib/maybe.lisp +++ b/stdlib/maybe.milch @@ -2,7 +2,7 @@ In order of priority +- Implement records and unions - Write function let expressions properly using lookups - Write tests! -- Come up with a name for the language -- Add effects system (see `examples/effects-concept.lisp`) +- Add effects system (see `examples/effects-concept.milch`) |
