Compare commits
	
		
			3 Commits
		
	
	
		
			0.12.0
			...
			0.12.0-hot
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 33c2119708 | |||
| 3b833ca75b | |||
| 203bc1898d | 
| @ -10,7 +10,7 @@ tricu is the word for "tree" in Lojban: `(x1) is a tree of species/cultivar (x2) | ||||
|  | ||||
| - Tree Calculus operator: `t` | ||||
| - Assignments: `x = t t` | ||||
| - Immutabile definitions | ||||
| - Immutable definitions | ||||
| - Lambda abstraction syntax: `id = (\a : a)` | ||||
| - List, Number, and String literals: `[(2) ("Hello")]`  | ||||
| - Function application: `not (not false)` | ||||
| @ -45,7 +45,7 @@ tricu > 12 | ||||
|  | ||||
| [Releases are available for Linux.](https://git.eversole.co/James/tricu/releases) | ||||
|  | ||||
| Or you can easily build and/or run this project using [Nix](https://nixos.org/download/). | ||||
| Or you can easily build and run this project using [Nix](https://nixos.org/download/). | ||||
|  | ||||
| - Quick Start (REPL):  | ||||
|   - `nix run git+https://git.eversole.co/James/tricu` | ||||
|  | ||||
							
								
								
									
										32
									
								
								src/Eval.hs
									
									
									
									
									
								
							
							
						
						
									
										32
									
								
								src/Eval.hs
									
									
									
									
									
								
							| @ -10,26 +10,26 @@ import qualified Data.Set as Set | ||||
|  | ||||
| evalSingle :: Env -> TricuAST -> Env | ||||
| evalSingle env term | ||||
|   | SDef name [] body <- term = | ||||
|       if | ||||
|         | Map.member name env -> | ||||
|             errorWithoutStackTrace $ | ||||
|               "Error: Identifier '" ++ name ++ "' is already defined." | ||||
|         | otherwise -> | ||||
|             let res = evalAST env body | ||||
|             in Map.insert "!result" res (Map.insert name res env) | ||||
|   | SApp func arg <- term = | ||||
|       let res = apply (evalAST env func) (evalAST env arg) | ||||
|   | SDef name [] body <- term | ||||
|   = case Map.lookup name env of | ||||
|       Just existingValue | ||||
|         | existingValue == evalAST env body -> env | ||||
|         | otherwise -> errorWithoutStackTrace $ | ||||
|             "Unable to rebind immutable identifier: '" ++ name | ||||
|       Nothing -> | ||||
|         let res = evalAST env body | ||||
|         in Map.insert "!result" res (Map.insert name res env) | ||||
|   | SApp func arg <- term  | ||||
|   = let res = apply (evalAST env func) (evalAST env arg) | ||||
|       in Map.insert "!result" res env | ||||
|   | SVar name <- term = | ||||
|       case Map.lookup name env of | ||||
|         Just v  -> | ||||
|           Map.insert "!result" v env | ||||
|   | SVar name <- term  | ||||
|   = case Map.lookup name env of | ||||
|         Just v  -> Map.insert "!result" v env | ||||
|         Nothing -> | ||||
|           errorWithoutStackTrace $ "Variable `" ++ name ++ "` not defined\n\ | ||||
|           \This error should never occur here. Please report this as an issue." | ||||
|   | otherwise = | ||||
|       Map.insert "!result" (evalAST env term) env | ||||
|   | otherwise  | ||||
|   = Map.insert "!result" (evalAST env term) env | ||||
|  | ||||
| evalTricu :: Env -> [TricuAST] -> Env | ||||
| evalTricu env x = go env (reorderDefs env x) | ||||
|  | ||||
| @ -60,8 +60,7 @@ main = do | ||||
|     Repl -> do | ||||
|       putStrLn "Welcome to the tricu REPL" | ||||
|       putStrLn "You can exit with `CTRL+D` or the `:_exit` command.`" | ||||
|       library <- liftIO $ evaluateFile "./lib/base.tri" | ||||
|       repl $ Map.delete "!result" library | ||||
|       repl Map.empty | ||||
|     Evaluate { file = filePaths, form = form } -> do | ||||
|       result <- case filePaths of | ||||
|         [] -> do | ||||
| @ -77,8 +76,7 @@ main = do | ||||
|       value <- case filePaths of | ||||
|         [] -> getContents | ||||
|         (filePath:_) -> readFile filePath | ||||
|       library <- liftIO $ evaluateFile "./lib/base.tri" | ||||
|       putStrLn $ decodeResult $ result $ evalTricu library $ parseTricu value | ||||
|       putStrLn $ decodeResult $ result $ evalTricu Map.empty $ parseTricu value | ||||
|  | ||||
| runTricu :: String -> T | ||||
| runTricu input = | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	