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