Extend the Funclang programming language from problem 6.9.1 to implement a substitution-based variation of the call expression

Question:

Extend the Funclang programming language from problem 6.9.1 to implement a substitution-based variation of the call expression (say [ ] expression). Recall that a substitution-based semantics works as follows. The value of [ (lambda (x y) (+ x y)) 3 4] is the value of a new expression created from the original function body (+ x y) by replacing x with 3 and y with 4. According to substitution-based semantics, the value of the call expression is the value of (+ 3 4), which is 7.

The grammar of this new language feature should be exactly the same as the grammar of the call expression in the Funclang language, except for the syntax [ ].

Implement substitution as a subst method for each AST node, such that given a list of variable names and a list of values, the subst method returns a copy of the current AST node with each free variable name substituted for the corresponding value.


Problem 6.9.1

Optimize the function call semantics by reducing the size of the environment saved in FunVal so that it contains only mappings from free variables in the function body to their bindings in the current environment.

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Question Posted: