X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=blobdiff_plain;f=code%2Fcalculator%2Fcalc5.ml;h=593f296beb805553ab85e636f43e4b99fec06544;hp=16e92006c255622d9a820d2cf98b08fb35feb233;hb=060198e29e2a13552ee64c1e489eea555c8b1cae;hpb=00ea8839bac58c3c1d53460dd34efc4722c8a6f2 diff --git a/code/calculator/calc5.ml b/code/calculator/calc5.ml index 16e92006..593f296b 100644 --- a/code/calculator/calc5.ml +++ b/code/calculator/calc5.ml @@ -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'') - | 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 @@ -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') - ), 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 *) @@ -94,12 +94,12 @@ (* we don't handle cases where t1 doesn't evaluate to a Pair *) let (Pair (index1, index2), s') = eval t1 g s (* note that s' may be different from s, if t1 itself contained any mutation operations *) - in let (new_value, s'') = eval t2 g s' - (* now we create a list which is just like s'' except it has new_value in index1 *) + in let (value2, s'') = eval t2 g s' + (* now we create a list which is just like s'' except it has value2 in index1 *) in let rec replace_nth lst m = match lst with | [] -> failwith "list too short" - | x::xs when m = 0 -> new_value :: xs + | x::xs when m = 0 -> value2 :: xs | x::xs -> x :: replace_nth xs (m - 1) in let s''' = replace_nth s'' index1 in (Int 42, s''')