refactor: simplify eval_let_expr parameters
This commit is contained in:
parent
1e172f80ef
commit
b503bd29e8
1 changed files with 7 additions and 2 deletions
|
@ -16,7 +16,7 @@ and function_type = {
|
||||||
let rec eval_expr (scope: scope) (expr: Parser.expr_tree): value_type =
|
let rec eval_expr (scope: scope) (expr: Parser.expr_tree): value_type =
|
||||||
match expr with
|
match expr with
|
||||||
| Parser.LetExpr (l) ->
|
| Parser.LetExpr (l) ->
|
||||||
eval_let_expr scope l.name l.value_expr l.in_expr
|
eval_let_expr scope l
|
||||||
| Parser.FunExpr (ftree) ->
|
| Parser.FunExpr (ftree) ->
|
||||||
eval_fun_expr scope ftree
|
eval_fun_expr scope ftree
|
||||||
| Parser.IfExpr (Parser.If (cond_expr, then_expr, else_expr)) ->
|
| Parser.IfExpr (Parser.If (cond_expr, then_expr, else_expr)) ->
|
||||||
|
@ -50,7 +50,12 @@ and eval_if_expr scope cond_expr then_expr else_expr =
|
||||||
(match cond with
|
(match cond with
|
||||||
| Int 0 -> eval_expr scope else_expr
|
| Int 0 -> eval_expr scope else_expr
|
||||||
| _ -> eval_expr scope then_expr)
|
| _ -> eval_expr scope then_expr)
|
||||||
and eval_let_expr scope name value_expr in_expr =
|
and eval_let_expr scope ({
|
||||||
|
name = name;
|
||||||
|
value_expr = value_expr;
|
||||||
|
in_expr = in_expr;
|
||||||
|
type_declare = _;
|
||||||
|
}: Parser.let_expr_tree) =
|
||||||
let value = eval_expr scope value_expr in
|
let value = eval_expr scope value_expr in
|
||||||
let new_scope = { scope with bindings = VariableBindingMap.add name value scope.bindings } in
|
let new_scope = { scope with bindings = VariableBindingMap.add name value scope.bindings } in
|
||||||
eval_expr new_scope in_expr
|
eval_expr new_scope in_expr
|
||||||
|
|
Loading…
Add table
Reference in a new issue