Substitution vs Enviroments

Mr.B
Mausschubser
Mausschubser
Beiträge: 65
Registriert: 13. Dez 2009 17:04

Substitution vs Enviroments

Beitrag von Mr.B »

Hey guys,

in the second lecture (v2) on slide 15 is a code snipped and the question how it is evaluated with substitution/enviroments.
I understand the difference between sub. and env. and their runtime specific dis-/advantages.
But i can't see the difference in evaluation. I'm not even sure if i get the code snipped :roll:

f is defined as f(x) = n?
So, wouldn't be the result of the compution be 5 in both cases?
I mean, in the substitution case n is substituted by 5 so f(x) = 5. In the enviroment case, n is looked up and since the example uses dynamic scoping n=5 aswell -> f(x)=5.

I'm sure I missunderstood someting there. Maybe you can clarify this.
Thanks in advance!

Best
Mr.B

r1chard
Erstie
Erstie
Beiträge: 19
Registriert: 26. Mai 2011 17:23

Re: Substitution vs Enviroment

Beitrag von r1chard »

Hi,

(slide 14)
the function definitions are a several input and for a "Let" you only subst. in the body and not in funDefs. (Only subst. on its static scope)
You only subst. the body of a function, when it is applied and then you only subst. the argument.
Therefore it would occur an error for the input, because n is neither the argument nor defined inside the function.

As you said the enviroment case would pass the enviroment out of the scope and result in 5.

Mr.B
Mausschubser
Mausschubser
Beiträge: 65
Registriert: 13. Dez 2009 17:04

Re: Substitution vs Enviroments

Beitrag von Mr.B »

That makes sense. Thx a lot mate!

Mr.B
Mausschubser
Mausschubser
Beiträge: 65
Registriert: 13. Dez 2009 17:04

Re: Substitution vs Enviroments

Beitrag von Mr.B »

Regarding this topic, another thing comes in my mind.

In Ex3 1.3 it is asked for an example where subst. and env. behave different. An example would be the one i gave in the threads opening post when the enviromental implemntation is dynamic scoped.
But in the case of a static scoped enviromental implementation wouln't it behave the same as a subst. driven implementation?
In other words, is there an example where an eviroment based, static scoped implementation behaves different to a substitution based implementation?

Best
Mr.B

LordHoto
BASIC-Programmierer
BASIC-Programmierer
Beiträge: 135
Registriert: 14. Dez 2009 17:00

Re: Substitution vs Enviroments

Beitrag von LordHoto »

Mr.B hat geschrieben:In Ex3 1.3 it is asked for an example where subst. and env. behave different. An example would be the one i gave in the threads opening post when the enviromental implemntation is dynamic scoped.
But in the case of a static scoped enviromental implementation wouln't it behave the same as a subst. driven implementation?
In other words, is there an example where an eviroment based, static scoped implementation behaves different to a substitution based implementation?
I think the idea was that code which has side effects evaluates differently in substitution vs environment. Think of a "let" which binds an expression which makes your programm terminate to a variable which is never used. If you have (lazy) substitution, it will not error out because the bound expression is never evaluated. If you use environments, your interpreter will evaluate the bound expression and then terminate.
Compiler 1 Tutor WS 12/13

Mr.B
Mausschubser
Mausschubser
Beiträge: 65
Registriert: 13. Dez 2009 17:04

Re: Substitution vs Enviroments

Beitrag von Mr.B »

That also makes sense to me, thx a lot!!

Does any of you know where I could find a test/old exam?

Antworten

Zurück zu „Archiv“