ASSIGNMENT 07 - FWAE INTERPRETER App

jandalf
Erstie
Erstie
Beiträge: 16
Registriert: 18. Apr 2015 20:36

ASSIGNMENT 07 - FWAE INTERPRETER App

Beitrag von jandalf »

Hello,

I have a very short question about the FWAE interpreter. Why is there a Let Node in the first argument of the App in fwaeLetFunApp?

Code: Alles auswählen

    val fwaeLetFunApp = Ctor('App, List(
      Ctor('Let, List(Sym('x), Ctor('Num, List(5)),
        Ctor('Fun, List(Sym('n), Ctor('Add, List(Ctor('Id, List(Sym('n))), Ctor('Id, List(Sym('x))))))))),
      Ctor('Num, List(7))))

In the interpreter code in the svn (FWAEDynamicInterp), it is defined like that:

Code: Alles auswählen

    
case App(funExpr, argExpr) => interp(funExpr, env) match {
      case Fun(param, body) => {
        interp(body, env + (param -> interp(argExpr, env)))
      }
      case _ => sys.error("Can only handle function expressions")
}
Therefore, I would have assumed that the Let in the test is wrong.

IvaToteva
Neuling
Neuling
Beiträge: 10
Registriert: 15. Apr 2015 16:41

Re: ASSIGNMENT 07 - FWAE INTERPRETER App

Beitrag von IvaToteva »

Hi,

The test is correct. Notice that the pattern matching is done on the result of interpreting the first expression, not on the expression itself. Therefore, the first expression does not need to be a function, it needs to evaluate to a function (or more precisely, a closure).

You should look into one of the static interpreters, we want to have static scoping and not dynamic scoping.

I hope this helps.

Best regards,
Iva

Antworten

Zurück zu „Archiv“