## Question concerning 2nd ex, Task 4

tzeenie
Mausschubser
Beiträge: 80
Registriert: 14. Okt 2008 20:04

### Question concerning 2nd ex, Task 4

Modify the procedure "lazy-calc" (currently an exact copy of "eager-calc") such that it substitutes lazily. Then write a test case that succeeds when using lazy substitution, but fails with eager substitution.
Mmh, I don't get it, is this a trick question? If the eager-calc method is our reference implementation, every implementation of lazy-calc that derives different results should be regarded erroneous, shouldn't it? So unless our implementation contains a bug, it should be impossible to write such a test case.

Christoph-D
Computerversteher
Beiträge: 325
Registriert: 11. Dez 2005 13:14

### Re: Question concerning 2nd ex, Task 4

tzeenie hat geschrieben:
Modify the procedure "lazy-calc" (currently an exact copy of "eager-calc") such that it substitutes lazily. Then write a test case that succeeds when using lazy substitution, but fails with eager substitution.
Mmh, I don't get it, is this a trick question? If the eager-calc method is our reference implementation, every implementation of lazy-calc that derives different results should be regarded erroneous, shouldn't it? So unless our implementation contains a bug, it should be impossible to write such a test case.
It's not a trick question and it's not impossible to write such a test case. You need to consider the difference between eager and lazy substition.
"I believe in the fundamental interconnectedness of all things." (Dirk Gently)

sewe
Sonntagsinformatiker
Beiträge: 295
Registriert: 16. Jan 2009 14:53
Kontaktdaten:

### Re: Question concerning 2nd ex, Task 4

Mmh, I don't get it, is this a trick question?
We reserve trick questions for the exercise. So, as Christoph-D already said, there are such test cases where a eager substitution regime produces error where a lazy one does not.

At any rate, here's a hint: you are too used to having a parser/compiler perform error checking for you. But our interpreter approach catches certain errors only at runtime. (Feel free to make the parse procedure smarter and perform error checking, if you want to get more insight into this particular issue.)

tzeenie
Mausschubser
Beiträge: 80
Registriert: 14. Okt 2008 20:04

### Re: Question concerning 2nd ex, Task 4

Ah, right, I implemented deferred substitution but with eager calculation, the terminology is just starting to settle in. Ok, but I'm still confused about the test case.

Don't get me wrong, I don't want anybody to post a ready-made solution, but I'd be glad if someone could point me into the right direction here: I think the question is aiming at dynamic scope, right? If you implement lazy-calc with dynamic scope

Code: Alles auswählen

(lazy-calc (emptySub) (parse '{with x y {with y 5 {+ x x}}}))
would evaluate to 10. Is this the implementation we should go for? My current implementation uses static scope and thus gives an unbound identifier error, just like eager-calc does. IMO dynamic scope does not make a lot of sense, the accompanying book agrees and states that dynamic scope should be considered an error (see p. 36, last paragraph before 5.3). Am I thinking in the wrong direction?

tzeenie
Mausschubser
Beiträge: 80
Registriert: 14. Okt 2008 20:04

### Re: Question concerning 2nd ex, Task 4

sewe hat geschrieben:At any rate, here's a hint: you are too used to having a parser/compiler perform error checking for you. But our interpreter approach catches certain errors only at runtime. (Feel free to make the parse procedure smarter and perform error checking, if you want to get more insight into this particular issue.)
Aaaaah, now I get it! Thanks a lot for the help!