From 88f7b0444146d9379521cc31ad9ef87b909e0b3b Mon Sep 17 00:00:00 2001 From: Jim Pryor Date: Thu, 25 Nov 2010 11:34:38 -0500 Subject: [PATCH] tweak calc improvements Signed-off-by: Jim Pryor --- advanced_topics/calculator_improvements.mdwn | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced_topics/calculator_improvements.mdwn b/advanced_topics/calculator_improvements.mdwn index e22afb1a..4f24f877 100644 --- a/advanced_topics/calculator_improvements.mdwn +++ b/advanced_topics/calculator_improvements.mdwn @@ -120,7 +120,7 @@ We can begin with our language: | Lambda of (char * term) | Apply of (term * term);; -Next, we need to expand our stock of `expressed_value`s to include function values as well. How should we think of these? We've several times mentioned the issue of how to handle free variables in a function's body, like the `x` in `lambda y -> y + x`. We'll follow the usual functional programming standard for these (known as "lexical scoping"), which keeps track of what value `x` has in the function expression's lexical environment. That shouldn't get shadowed by any different value `x` may have when the function value is later applied. So: +Next, we need to expand our stock of `expressed_value`s to include function values as well. How should we think of these? We've several times mentioned the issue of how to handle free variables in a function's body, like the `x` in `lambda y -> y + x`. We'll follow the usual functional programming standard for these (known as "lexical scoping"), which keeps track of what value `x` has in the function declaration's lexical environment. That shouldn't get shadowed by any different value `x` may have when the function value is later applied. So: let x = 1 in let f = lambda y -> y + x in let x = 2 in apply f 2 @@ -157,7 +157,7 @@ Now our evaluation function needs two further clauses to interpret the two new e There are different ways to include recursion in our calculator. First, let's imagine our language expanded like this: - let x = 1 in letrec f = lambda y -> if iszero y then x else y * f (y - 1) in f 3 + let x = 1 in letrec f = lambda y -> if iszero y then x else y * apply f (y - 1) in apply f 3 where the AST would be: -- 2.11.0