Exercise 3: error in tests?

spyro.makedonski
BASIC-Programmierer
BASIC-Programmierer
Beiträge: 102
Registriert: 18. Apr 2010 13:45

Exercise 3: error in tests?

Beitrag von spyro.makedonski »

Task 2 following test:

Code: Alles auswählen

 def testZeroArg2 {
    expect(Fun('_, Num(3))) {
      interp(preproc(SWith('c, SFun(List(), 3), 'c)))
    }
  }
interp returns Int right? Why is FWAE expected then?

Second question:

Are you sure that interp deals correctly with

Code: Alles auswählen

Fun('_, Num(3))
... are you sure it knows how to deal with the '_.

thanks

Benutzeravatar
cofi
Mausschubser
Mausschubser
Beiträge: 86
Registriert: 22. Sep 2009 12:07

Re: Exercise 3: error in tests?

Beitrag von cofi »

@1: `interp` returns that what is specified .. and that is FWAE, it is _not_ the previous `interp`.

@2: `interp` does not have to deal with that. What is here returned is the function itself, because it is not called. And then the given Fun is nothing new for `interp` because it is a function with one argument.

spyro.makedonski
BASIC-Programmierer
BASIC-Programmierer
Beiträge: 102
Registriert: 18. Apr 2010 13:45

Re: Exercise 3: error in tests?

Beitrag von spyro.makedonski »

thanks for your reply!

i am totally confused ...10/11 Specification tests passed. All visible tests passed except one:

Code: Alles auswählen

def testZeroArg1 {
    expect (Num(3)) {
      interp(preproc(SWith('c, SFun(List(), 3), SApp('c, List()))))
    }
  }

Code: Alles auswählen

Test testZeroArg1 failed: Expected Num(3), but got Fun('_,Num(3))

obviously the interp expects evaluated Fun when there are no arguments(meaning it expects the value directly). If i am to make this test work, then the test

Code: Alles auswählen

  def testZeroArg2 {
    expect(Fun('_, Num(3))) {
      interp(preproc(SWith('c, SFun(List(), 3), 'c)))
    }
  }
gets broken, because in it interp does not expect me to evaluate the Fun ... in this case i would get the oposite error message "Expected Fun('_,Num(3)), but got Num(3)"
those 2 tests seem to be in conflict with one another. Are you sure that the solution passes all tests?

regards

Benutzeravatar
cofi
Mausschubser
Mausschubser
Beiträge: 86
Registriert: 22. Sep 2009 12:07

Re: Exercise 3: error in tests?

Beitrag von cofi »

The two tests don't conflict: ZeroArg1 has a function application, ZeroArg2 has not.

spyro.makedonski
BASIC-Programmierer
BASIC-Programmierer
Beiträge: 102
Registriert: 18. Apr 2010 13:45

Re: Exercise 3: error in tests?

Beitrag von spyro.makedonski »

But as i understand it, it is not the preprocessor's job to do the substitutions... the interpreter is supposed to do the substitions. When the preprocessor receives the SApp type from the test, it does not see the SFun type, unless we store it in some global Map as environment. Are we supposed to do that?
Obviously i am missing something ... :(

Benutzeravatar
cofi
Mausschubser
Mausschubser
Beiträge: 86
Registriert: 22. Sep 2009 12:07

Re: Exercise 3: error in tests?

Beitrag von cofi »

Again: The tests do two different things and they are compatible with each other.
When the preprocessor receives the SApp type from the test, it does not see the SFun type
No, but as you have to rewrite SApp to App you obviously have to rewrite its funExpr and args as well.

Read the tests carefully until you understand how 0-parameter functions should be represented and then think about how a function application with 0-args should be represented. And: Dropping such an application is not an option.

spyro.makedonski
BASIC-Programmierer
BASIC-Programmierer
Beiträge: 102
Registriert: 18. Apr 2010 13:45

Re: Exercise 3: error in tests?

Beitrag von spyro.makedonski »

ok it works now... thanks for your help

Antworten

Zurück zu „Archiv“