Mistake in assignment 3, task 3

Benutzeravatar
sewe
Sonntagsinformatiker
Sonntagsinformatiker
Beiträge: 295
Registriert: 16. Jan 2009 14:53
Kontaktdaten:

Mistake in assignment 3, task 3

Beitrag von sewe »

There has been a slight mistake in the test cases for the third task of assignment 3 (Thanks to Norbert Fabritius for pointing this out.): The second of the commented-out test cases should read as follows

Code: Alles auswählen

(test (interp (parse (preproc (with {c {fun {} 3}} c)))) (fun '_ (num 3)))
Note that the function literal does have a single argument, namely the symbol _, and not an empty list. The repository has been updated already; please merge.

Benutzeravatar
Maradatscha
Computerversteher
Computerversteher
Beiträge: 353
Registriert: 2. Okt 2006 18:53

Re: Mistake in assignment 3, task 3

Beitrag von Maradatscha »

Did you forget the ' ?
The tests won't run as they are in the svn right now.

Code: Alles auswählen

(test (interp (parse (preproc '(with {c {fun {} 3}} {c})))) (num 3))
(test (interp (parse (preproc '(with {c {fun {} 3}} c)))) (fun '_ (num 3)))

Benutzeravatar
sewe
Sonntagsinformatiker
Sonntagsinformatiker
Beiträge: 295
Registriert: 16. Jan 2009 14:53
Kontaktdaten:

Re: Mistake in assignment 3, task 3

Beitrag von sewe »

The SVN now contains a number of test cases that should make the whole matter clearer:

Code: Alles auswählen

(test (parse (preproc '{fun {} 3})) (parse '{fun {_} 3})) ; Handle zero-argument functions with a dummy parameter named _.
(test (interp (parse (preproc '{with {c {fun {} 3}} {c}}))) (num 3)) ; Handle zero-argument calls. (What to pass in as single argument?)
(test (interp (parse (preproc '{with {c {fun {} 3}} c}))) (fun '_ (num 3))) ; Handle function literals and distinguish them from zero-argument calls.
As you can see, handling zero-parameter function definitions and zero-argument functions calls is quite a different beast from your plain ol' currying (illustrated by the test cases below, which can also be found in the SVN now).

Code: Alles auswählen

(test (parse (preproc '{fun {a b} {- a b}})) (parse '{fun {a} {fun {b} {- a b}}}))
(test (parse (preproc '{f a b})) (parse '{{f a} b}))
(test (parse (preproc '{{fun {a b} {- a b}} 1 2})) (parse '{{{fun {a} {fun {b} {- a b}}} 1} 2}))
(test (interp (parse (preproc '{{fun {a b} {- a b}} 1 2}))) (num -1))
(test (interp (parse (preproc '{with {f {fun {a b} {- a b}}} {f 1 2}}))) (num -1))
Please update your working copy yet again. Sorry about that. :oops: (With hindsight I should have separated the multiple-parameter case from the zero-parameter case.)

Antworten

Zurück zu „Archiv“