Answered step by step
Verified Expert Solution
Question
1 Approved Answer
leave free variables as is . > ( lex ' ( lambda ( x ) x ) ' ( ) ) ( lambda ( var
leave free variables as is
lex lambda x x
lambda var
lex lambda ylambda x y
lambda lambda var
lex lambda ylambda xx y
lambda lambda var var
lex lambda xlambda xx x
lambda lambda var var
lex lambda xlambda xy x
lambda lambda y var
lex lambda ylambda xx ylambda clambda dy c
lambda lambda var var lambda lambda var var
lex lambda a
lambda b
lambda c
lambda a
lambda b
lambda d
lambda a
lambda e
a b c d e a
lambda
lambda
lambda
lambda
lambda
lambda
lambda
lambda
var var var var var var
lex lambda a
lambda b
lambda c
lambda w
lambda x
lambda y
lambda a
lambda b
lambda c
a b c w x y
lambda w
lambda x
lambda y
a b c w x y
lambda
lambda
lambda
lambda
lambda
lambda
lambda
lambda
lambda
var var var var var var
lambda
lambda
lambda
var var var var var var
lex lambda a
lambda b
lambda c
lambda w
lambda x
lambda y
lambda a
lambda b
lambda c
a b c w x y
lambda w
lambda x
lambda y
a b c w h y
lambda
lambda
lambda
lambda
lambda
lambda
lambda
lambda
lambda var var var var var var
lambda
lambda
lambda var var var var hvar
There are a number of ways you can approach this problem. Our suggestion is to build some lambda expressions with pen and paper, and then by hand find the lexical addresses of some variables that occur in them. Try and do it almost mechanically, starting from the body of the innermost lambda of the expression and working your way out. If there is more than one innermost lambda, pick one, resolve it and repeat. Then think about what it is youre doing, and figure out how to do it without having to go back up the tree. That is ensure that when you get to a variable position in the expression where you need to fill in the lexical address, that you already have all the information you need to figure it out.
Part : Interpreters and Higher Order Function Representation
In recent lectures, weve learned how to write an interpreter that takes a Racket expression and returns the result of evaluating that expression. We have also learned to make it representation independent with respect to environments and closures. We have written helper functions that manipulate the representations of environments and closures: extendenv, applyenv, emptyenv, applyclos and makeclos. In Part we will implement two interpreters in total: the basic representation dependent RD interpreter, and the representation independent RI interpreter, along with helper functions for the RI interpreter.
You must define a set of environment helpers: that uses functional higherorder representation of environments. Call the representationdependent version valueof and the representation independent version valueoffn
Notice these names may be different from those presented in lecture. This is a framework for how you should name your procedures and helpers:
define valueof
define valueoffn
define emptyenvfn
define extendenvfn
define applyenvfn
define applyclosfn
define makeclosfn
Your interpreter must handle the following forms: numbers, booleans, variables, lambdaabstraction application, zero?, sub if and let
Unlike in Racket, here let can bind only one variable.
Remember, your solutions should be compositional.
You may have seen the expansion of let x e body as lambda x body e When you are comfortable with the environment, however, you can implement let without using
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started