Now when a var is evaluated, the new evaluation replaces the old

This commit is contained in:
Ivy 2021-01-30 00:55:05 +01:00
parent 2a351374a7
commit c15a736236
2 changed files with 8 additions and 7 deletions

View File

@ -15,8 +15,9 @@ base = M.fromList [
eval :: Env -> Expr -> (Env, Expr) eval :: Env -> Expr -> (Env, Expr)
eval env (IntE x) = (env, IntE x) eval env (IntE x) = (env, IntE x)
eval env (VarE v) = eval env $ env M.! v eval env (VarE v) = (M.insert v nExpr nEnv, nExpr)
eval env (SetE v expr) = (M.insert v expr env, expr) where (nEnv, nExpr) = eval env $ env M.! v
eval env (SetE v expr) = (M.insert v expr env, NilE)
eval env NilE = (env, NilE) eval env NilE = (env, NilE)
--apply :: Proc -> Args -> Expr --apply :: Proc -> Args -> Expr

View File

@ -4,9 +4,9 @@ data Expr = IntE Integer
| VarE String | VarE String
| ProcedureE String [Expr] | ProcedureE String [Expr]
| SetE String Expr | SetE String Expr
| NilE | NilE deriving (Show)
instance Show Expr where -- instance Show Expr where
show (IntE x) = show x -- show (IntE x) = show x
show (VarE x) = x ++ " ; var" -- show (VarE x) = x ++ " ; var"
show NilE = "nil" -- show NilE = "nil"