since there are no sample solutions, is anyone interessted in discussing some exercises?
I'll start with ex.3 and will probably add more. Feel free to comment...
best, plo1234# Exercise 03
## Task 1: Immediate substitution vs deferred substitution
For the language F1WAE, we introduced environments as an alternative for
substitutions.
### 1. Why did we do this?
Increase efficiency: we don't have to traverse the whole program
(especially unvisited branches) for substitution before actually
interpreting.
### 2.Discuss the advantages and disadvantages of substitution versus environments.
* Substitution is hard to get right
* Environments are more efficient
### 3. Write F1WAE examples that notably behave differently when run with an interpreter that uses substitution versus environments.
Anyone?
## Task 2: Scoping
### 1. What is the difference between dynamic scoping and static (lexical) scoping?
With static scoping a name always refers to its lexically "closest" binding
(?). With dynamic scoping a name always refers to the value that has been
bound to the name most recently.
### 2. What does ‘static’ stand for in static scoping?
The scope of a name can be determined statically (at compile time), like in
static-analysis.
### 3. Why is dynamic scoping bad?
* it is counter-intuitive
* we cannot see the scope of a name only by looking at the code
## Task 3: Deferred substitutions and closures
Consider the interpreters for FWAE.
### 1. In the interpreter with environments we introduced closures. What is a closure? What do we need them for?
A closure is a function plus the environment at the time the closure has
been created. We needed Closures because in the interpreter with
environments, we have to save the current environment when we encouter a
function defintion.
### 2. Why did we not need closures in the interpreter with substitution?
Because all bound instances are substituted as soon as the interpreter
encounters a function definition.
### 3. Why did we not need closures in the F1WAE interpreter with environments?
Because only arguments and local variables are in the scope of F1-Functions.
Things like this are not possible:
val funDefs = Map('f -> FunDef('n, Add('n, 'x)))
i