tweak calc improvements
authorJim Pryor <profjim@jimpryor.net>
Fri, 26 Nov 2010 03:40:39 +0000 (22:40 -0500)
committerJim Pryor <profjim@jimpryor.net>
Fri, 26 Nov 2010 03:40:39 +0000 (22:40 -0500)
Signed-off-by: Jim Pryor <profjim@jimpryor.net>
advanced_topics/calculator_improvements.mdwn
code/calculator/calc4.ml
code/calculator/calc5.ml

index 3e51c95..280604f 100644 (file)
@@ -369,7 +369,7 @@ Our evaluation function will now expect a `store` argument as well as an `assign
        let rec eval (t : term) (g : assignment) (s : store) = match t with
          Intconstant x -> (Int x, s)
          ...
        let rec eval (t : term) (g : assignment) (s : store) = match t with
          Intconstant x -> (Int x, s)
          ...
-       | Variable (var) -> (
+       | Variable (var) -> ((
                (* we don't handle cases where g doesn't bind var to any value *)
                match List.assoc var g with
           | Nonrecursive value -> value
                (* we don't handle cases where g doesn't bind var to any value *)
                match List.assoc var g with
           | Nonrecursive value -> value
@@ -377,7 +377,7 @@ Our evaluation function will now expect a `store` argument as well as an `assign
                          (* we update savedg to bind self_var to rec_closure here *)
               let savedg' = (self_var, rec_closure) :: savedg
               in Closure (arg_var, body, savedg')
                          (* we update savedg to bind self_var to rec_closure here *)
               let savedg' = (self_var, rec_closure) :: savedg
               in Closure (arg_var, body, savedg')
-        ), s
+        ), s)
          ...
        | Lambda (arg_var, t2) -> (Closure (arg_var, t2, g), s)
          ...
          ...
        | Lambda (arg_var, t2) -> (Closure (arg_var, t2, g), s)
          ...
index 378e037..a04587b 100644 (file)
@@ -38,7 +38,7 @@
         let (Int i1, s') = eval t1 g s
         in let (Int i2, s'') = eval t2 g s'
         in (Int (i1 + i2), s'')
         let (Int i1, s') = eval t1 g s
         in let (Int i2, s'') = eval t2 g s'
         in (Int (i1 + i2), s'')
-    | Variable (var) -> (
+    | Variable (var) -> ((
         (* we don't handle cases where g doesn't bind var to any value *)
         match List.assoc var g with
           | Nonrecursive value -> value
         (* we don't handle cases where g doesn't bind var to any value *)
         match List.assoc var g with
           | Nonrecursive value -> value
@@ -46,7 +46,7 @@
               (* we update savedg to bind self_var to rec_closure here *)
               let savedg' = (self_var, rec_closure) :: savedg
               in Closure (arg_var, body, savedg')
               (* we update savedg to bind self_var to rec_closure here *)
               let savedg' = (self_var, rec_closure) :: savedg
               in Closure (arg_var, body, savedg')
-        ), s
+        ), s)
     | Let (var_to_bind, t2, t3) ->
         (* evaluate t3 under a new assignment where var_to_bind has been bound to
            the result of evaluating t2 under the current assignment *)
     | Let (var_to_bind, t2, t3) ->
         (* evaluate t3 under a new assignment where var_to_bind has been bound to
            the result of evaluating t2 under the current assignment *)
index 16e9200..2f533af 100644 (file)
@@ -36,7 +36,7 @@
         let (Int i1, s') = eval t1 g s
         in let (Int i2, s'') = eval t2 g s'
         in (Int (i1 + i2), s'')
         let (Int i1, s') = eval t1 g s
         in let (Int i2, s'') = eval t2 g s'
         in (Int (i1 + i2), s'')
-    | Variable (var) -> (
+    | Variable (var) -> ((
         (* we don't handle cases where g doesn't bind var to any value *)
         match List.assoc var g with
           | Nonrecursive value -> value
         (* we don't handle cases where g doesn't bind var to any value *)
         match List.assoc var g with
           | Nonrecursive value -> value
@@ -44,7 +44,7 @@
               (* we update savedg to bind self_var to rec_closure here *)
               let savedg' = (self_var, rec_closure) :: savedg
               in Closure (arg_var, body, savedg')
               (* we update savedg to bind self_var to rec_closure here *)
               let savedg' = (self_var, rec_closure) :: savedg
               in Closure (arg_var, body, savedg')
-        ), s
+        ), s)
     | Let (var_to_bind, t2, t3) ->
         (* evaluate t3 under a new assignment where var_to_bind has been bound to
            the result of evaluating t2 under the current assignment *)
     | Let (var_to_bind, t2, t3) ->
         (* evaluate t3 under a new assignment where var_to_bind has been bound to
            the result of evaluating t2 under the current assignment *)