diff options
Diffstat (limited to 'src/Evaluator.hs')
-rw-r--r-- | src/Evaluator.hs | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/Evaluator.hs b/src/Evaluator.hs index 1cc9edd..3d3be02 100644 --- a/src/Evaluator.hs +++ b/src/Evaluator.hs | |||
@@ -19,9 +19,9 @@ apply fn args = maybe | |||
19 | evalUnquote :: Env -> Expr -> IOResult Expr | 19 | evalUnquote :: Env -> Expr -> IOResult Expr |
20 | evalUnquote env (List [Id "unquote", vs]) = eval env vs | 20 | evalUnquote env (List [Id "unquote", vs]) = eval env vs |
21 | evalUnquote env (List [Id "quote", vs]) = | 21 | evalUnquote env (List [Id "quote", vs]) = |
22 | liftM (List . ([Id "quote"] ++ ) . (: [])) (evalUnquote env vs) | 22 | fmap (List . ([Id "quote"] ++ ) . (: [])) (evalUnquote env vs) |
23 | evalUnquote env (List vs) = liftM List $ mapM (evalUnquote env) vs | 23 | evalUnquote env (List vs) = List <$> mapM (evalUnquote env) vs |
24 | evalUnquote env (Vector vs) = liftM Vector $ mapM (evalUnquote env) vs | 24 | evalUnquote env (Vector vs) = Vector <$> mapM (evalUnquote env) vs |
25 | evalUnquote env literal = return literal | 25 | evalUnquote env literal = return literal |
26 | 26 | ||
27 | evalQuasiQuote :: Env -> Expr -> IOResult Expr | 27 | evalQuasiQuote :: Env -> Expr -> IOResult Expr |
@@ -35,12 +35,12 @@ eval _ v@(IntLiteral i) = return v | |||
35 | eval _ v@(BoolLiteral b) = return v | 35 | eval _ v@(BoolLiteral b) = return v |
36 | eval env (Id l) = getVar env l | 36 | eval env (Id l) = getVar env l |
37 | eval _ v@(FloatLiteral f) = return v | 37 | eval _ v@(FloatLiteral f) = return v |
38 | eval env v@(Vector xs) = liftM Vector $ mapM (eval env) xs | 38 | eval env v@(Vector xs) = Vector <$> mapM (eval env) xs |
39 | eval env (List[Id "quote", val]) = return val | 39 | eval env (List[Id "quote", val]) = return val |
40 | eval env (List[Id "quasiquote", val]) = evalQuasiQuote env val | 40 | eval env (List[Id "quasiquote", val]) = evalQuasiQuote env val |
41 | eval env v@(List[Id "unquote", val]) = throwError $ BadForm "Cannot use `unquote` form outside quasiquote context" v | 41 | eval env v@(List[Id "unquote", val]) = throwError $ BadForm "Cannot use `unquote` outside quasiquote form" v |
42 | eval env (List [Id "set!", Id var, val]) = eval env val >>= uncurry (*>) . ((setVar env var) &&& pure) | 42 | eval env (List [Id "set!", Id var, val]) = eval env val >>= uncurry (*>) . (setVar env var &&& pure) |
43 | eval env (List [Id "define", Id var, val]) = eval env val >>= uncurry (*>) . ((defineVar env var) &&& pure) | 43 | eval env (List [Id "define", Id var, val]) = eval env val >>= uncurry (*>) . (defineVar env var &&& pure) |
44 | eval env (List (Id fn : args)) = mapM (eval env) args >>= liftLispResult . apply fn | 44 | eval env (List (Id fn : args)) = mapM (eval env) args >>= liftLispResult . apply fn |
45 | eval env NoReturn = throwError $ BadForm "Invalid usage of non-returning expression" NoReturn | 45 | eval env NoReturn = throwError $ BadForm "Invalid usage of non-returning expression" NoReturn |
46 | 46 | ||