Typo in DeBrujinTest [test("conv ref in named expression")]

Moderator: Konzepte der Programmiersprachen

tud_std
Erstie
Erstie
Beiträge: 19
Registriert: 13. Apr 2016 16:29

Typo in DeBrujinTest [test("conv ref in named expression")]

Beitrag von tud_std » 10. Nov 2018 17:54

Dear Sirs,

I have another question regarding Task1 please. I am wondering why the following expression :

Code: Alles auswählen

 test("conv ref in named expression") {
    assertResult(LetDB(42, LetDB(RefDB(0), RefDB(0)))) {
      convert(Let('x, 42, Let('y, 'x, 'y)))
    }
  }
evaluates to

Code: Alles auswählen

LetDB(42, LetDB(RefDB(0), RefDB(0))) 
and not

Code: Alles auswählen

LetDB(42, LetDB(RefDB(1), RefDB(0)))
.
I think the x in the inner Let is bound to the x variable in the outter Let. The examples provided in Slide 9 of SIMPLE LANGUAGES lecture (i.e. V02.pdf) suggest the same.

I hope someone could clear up this to me. Thank you in advance.

Regards.

a10r
Erstie
Erstie
Beiträge: 11
Registriert: 4. Nov 2012 13:53

Re: Typo in DeBrujinTest [test("conv ref in named expression")]

Beitrag von a10r » 11. Nov 2018 10:45

You're correct in that the 'x in the named expression of the inner Let refers to the 'x that was defined in the outer Let. What is important to realize here is that Let has two sub-expressions: namedExpr and body. However, the list of bindings available in these sub-expressions is different. The two instances of RefDB(0) correspond to different original variables.

If you look at the inner Let, the namedExpr has one available binding: 'x = 42 (defined in the outer Let). The namedExpr is Id('x), so it becomes RefDB(0) after conversion. The body of the inner Let has two available bindings: 'x = 42; 'y (= 'x) = 42. The body is Id('y), so it also becomes RefDB(0) after conversion.

Antworten

Zurück zu „Konzepte der Programmiersprachen“