Seite 1 von 1

Assignment03: PreprocMultiarg test issue

Verfasst: 13. Nov 2019 08:55
von Locke
In the Assignment03 for the second Task (PreprocMultiarg) the second test case seems wrong:

Code: Alles auswählen

    // (testname,
    //  expected,
    //  actual),
    // first case [...]

    ("preproc app zero arg",
      LApp(LFun('_, 3), LNum(42)), // dummy value 42
      preprocMultiarg(MLApp(MLFun(List(), 3), List()))),
The expected result contains LNum(42) whereas that argument is never passed to preprocMultiarg. I believe the test should look like:

Code: Alles auswählen

preprocMultiarg(MLApp(MLFun(List(), 3), List(42)))),

Re: Assignment03: PreprocMultiarg test issue

Verfasst: 14. Nov 2019 01:05
von jkapitzke
The test is basically testing a function without arguments. Since with MFLAE we can have multiple or no arguments (empty list) If we transform that to our language where each function must have exactly (!) one argument, we have a problem with the functions that have no arguments.

The tests solve that by introducing arbitrary dummy values and dummy argument names. A dummy argument name is '_ and a dummy value is 42. Since in the body the dummy argument name is never used, the actual value of that dummy does not matter and can be arbitrary.

Example with scala function:

Code: Alles auswählen

val f = () => 3 // function without arguments. 

// We want to transform this function into a function with exactly one argument:
val f = (x) => 3 // function transformed to contain exactly one argument

// When we apply the function to a value (e.g. 42), the value does not matter
print(f(42)) // returns 3 (value 42 is ignored)
The tests make us choose a very specific dummy value (I think it is 42 for all cases). This should be specified in the requirements or the given tests should be designed in such a way that they allow any dummy value (this would probably make the tests less readable). Again, in theory, you can choose an arbitrary value, but for the tests we probably need to agree upon a certain value.