diff options
| author | Jan Tuomi <jans.tuomi@gmail.com> | 2022-09-27 12:35:27 +0300 |
|---|---|---|
| committer | Jan Tuomi <jans.tuomi@gmail.com> | 2022-12-05 14:21:53 +0200 |
| commit | 2952ecc005466775c9ac70a702da1bbad17a28e5 (patch) | |
| tree | cc4743d8615197c48c415455b838767419a63e57 | |
| parent | 6e55d34719f89192c9141f50638c6dc5bba71dff (diff) | |
Add eq?, lt?
| -rw-r--r-- | src/Builtins.hs | 17 | ||||
| -rw-r--r-- | src/Evaluator.hs | 1 | ||||
| -rw-r--r-- | todo.md | 1 |
3 files changed, 17 insertions, 2 deletions
diff --git a/src/Builtins.hs b/src/Builtins.hs index 0ddf89f..2dac829 100644 --- a/src/Builtins.hs +++ b/src/Builtins.hs @@ -13,6 +13,9 @@ builtinEnv = M.fromList [ builtinSubtract2, builtinMultiply2, builtinDivide2, + -- comparisons + builtinEq2, + builtinLt2, -- conversions builtinFmt, builtinFloor, @@ -106,6 +109,20 @@ builtinDivide2 = (name, ASTFunction fn1) where fn2 _ ast2 = throwL $ argError2 name ast1 ast2 fn1 _ ast1 = throwL $ argError1 name ast1 +builtinEq2 :: (String, AST) +builtinEq2 = (name, ASTFunction fn1) where + name = "eq?" + fn1 _ ast1 = + return $ ASTFunction $ fn2 where + fn2 _ ast2 = return $ ASTBoolean $ ast1 == ast2 + +builtinLt2 :: (String, AST) +builtinLt2 = (name, ASTFunction fn1) where + name = "lt?" + fn1 _ ast1 = + return $ ASTFunction $ fn2 where + fn2 _ ast2 = return $ ASTBoolean $ ast1 <= ast2 + builtinFloor :: (String, AST) builtinFloor = (name, ASTFunction fn1) where name = "floor" diff --git a/src/Evaluator.hs b/src/Evaluator.hs index a0c6151..009f108 100644 --- a/src/Evaluator.hs +++ b/src/Evaluator.hs @@ -117,7 +117,6 @@ evaluateMatch env args = do ++ "- matching on expr: " ++ show actualExpr ++ "\n" ++ "- arguments: " ++ show rest) - (_, evaledActual) <- evaluate env actualExpr ret <- matchPairs (actualExpr, evaledActual) pairs return (env, ret) @@ -3,7 +3,6 @@ In order of priority - Write tests! -- Add builtins to compare numbers (eq?, lt?) - Add import function with support for qualified imports - Come up with a name for the language - Add auto import for standard library (std) and a flag to disable auto import |
