X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=blobdiff_plain;f=advanced_topics%2Fcalculator_improvements.mdwn;h=b36f6287da195cf8aec228023c1b10be7c140688;hp=3e51c95b992d90170d8a87044b860312fc382fd1;hb=ee6e8e390ac5ffa57dc95531939222efda5d37ff;hpb=1fd1fc4930f5d25e7de28532cdefbe103d4b3a1b diff --git a/advanced_topics/calculator_improvements.mdwn b/advanced_topics/calculator_improvements.mdwn index 3e51c95b..b36f6287 100644 --- a/advanced_topics/calculator_improvements.mdwn +++ b/advanced_topics/calculator_improvements.mdwn @@ -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) ... - | 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 @@ -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') - ), s + ), s) ... | Lambda (arg_var, t2) -> (Closure (arg_var, t2, g), s) ... @@ -448,12 +448,12 @@ Now we need to formulate the clauses for evaluating the new forms `Newref (...)` ... | Newref (t1) -> - let (starting_val, s') = eval t1 g s + let (value1, s') = eval t1 g s (* note that s' may be different from s, if t1 itself contained any mutation operations *) (* now we want to retrieve the next free index in s' *) in let new_index = List.length s' - (* now we want to insert starting_val there; the following is an easy but inefficient way to do it *) - in let s'' = List.append s' [starting_val] + (* now we want to insert value1 there; the following is an easy but inefficient way to do it *) + in let s'' = List.append s' [value1] (* now we return a pair of a wrapped new_index, and the new store *) in (Mutcell new_index, s'') | Deref (t1) ->