tweak calc improvements
authorJim Pryor <profjim@jimpryor.net>
Thu, 25 Nov 2010 16:37:43 +0000 (11:37 -0500)
committerJim Pryor <profjim@jimpryor.net>
Thu, 25 Nov 2010 16:37:43 +0000 (11:37 -0500)
Signed-off-by: Jim Pryor <profjim@jimpryor.net>
advanced_topics/calculator_improvements.mdwn

index 4f24f87..cbf4c89 100644 (file)
@@ -145,9 +145,9 @@ Now our evaluation function needs two further clauses to interpret the two new e
        ...
        | Lambda(arg_var, t1) -> Closure (arg_var, t1, g)
        | Apply(t1, t2) ->
-               let value2 = eval t2 g
                (* we don't handle cases where t1 doesn't evaluate to a function value *)
-               in let Closure (arg_var, body, savedg) = eval t1 g
+               let Closure (arg_var, body, savedg) = eval t1 g
+               in let value2 = eval t2 g
                (* evaluate body under savedg, except with arg_var bound to value2 *)
                in let savedg' = (arg_var, value2) :: savedg
                in eval body savedg';;
@@ -276,9 +276,9 @@ Since we're not permitting ourselves OCaml's ability to recursively define cycli
        ...
        | Lambda(arg_var, t1) -> Closure (arg_var, t1, g)
        | Apply(t1, t2) ->
-               let value2 = eval t2 g
                (* we don't handle cases where t1 doesn't evaluate to a function value *)
-               in let Closure (arg_var, body, savedg) = eval t1 g
+               let Closure (arg_var, body, savedg) = eval t1 g
+               in let value2 = eval t2 g
                (* evaluate body under savedg, except with arg_var bound to Nonrecursive value2 *)
                in let savedg' = (arg_var, Nonrecursive value2) :: savedg
                in eval body savedg'