Second assignment now available

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

Second assignment now available

Beitrag von sewe »

The second assignment (6 Tasks, 10 points overall) is now available: https://cage.st.informatik.tu-darmstadt ... 012-04-20/. Please note: This assignment consists of two parts/files.

This assignment is due on Thursday, 26 April 2012, 23:59. Please commit your solution till then into your group's SVN directory under a subdirectory named 2012-04-20: https://cage.st.informatik.tu-darmstadt ... pt[12].rkt.

Benutzeravatar
olg
Sonntagsinformatiker
Sonntagsinformatiker
Beiträge: 297
Registriert: 1. Okt 2008 19:24

Re: Second assignment now available

Beitrag von olg »

The test cases for the fibonacci numbers in exercise02 - Task 2 differ from the fibonacci numbers defined in the OEIS (1, 2).

Code: Alles auswählen

(test (interp (parse '{fib 0}) fib-defs) 1) ;; 0
(test (interp (parse '{fib 1}) fib-defs) 1) ;; 1
(test (interp (parse '{fib 2}) fib-defs) 2) ;; 1 
(test (interp (parse '{fib 3}) fib-defs) 3) ;; 2
(test (interp (parse '{fib 4}) fib-defs) 5) ;; 3
(test (interp (parse '{fib 5}) fib-defs) 8) ;; 5
(test (interp (parse '{fib 6}) fib-defs) 13) ;; 8
Are we supposed to follow this definition (i.e., fib(0) = 1) of the fibonacci numbers, or is this an error in your tests?
If so, the following patch corrects the affected tests:

Code: Alles auswählen

--- assignment-pt1.rkt	2012-04-20 12:08:46.000000000 +0200
+++ assignment-pt1-corrected.rkt	2012-04-20 12:00:55.000000000 +0200
@@ -127,13 +127,14 @@
 
 (define fib-defs (list (fundef 'fib 'n (parse 'n))))
 
-;(test (interp (parse '{fib 0}) fib-defs) 1)
+;(test (interp (parse '{fib 0}) fib-defs) 0)
 ;(test (interp (parse '{fib 1}) fib-defs) 1)
-;(test (interp (parse '{fib 2}) fib-defs) 2)
-;(test (interp (parse '{fib 3}) fib-defs) 3)
-;(test (interp (parse '{fib 4}) fib-defs) 5)
-;(test (interp (parse '{fib 5}) fib-defs) 8)
-;(test (interp (parse '{fib 6}) fib-defs) 13)
+;(test (interp (parse '{fib 2}) fib-defs) 1)
+;(test (interp (parse '{fib 3}) fib-defs) 2)
+;(test (interp (parse '{fib 4}) fib-defs) 3)
+;(test (interp (parse '{fib 5}) fib-defs) 5)
+;(test (interp (parse '{fib 6}) fib-defs) 8)
+;(test (interp (parse '{fib 7}) fib-defs) 13)
 
 ;; **** Task 3 **** (1 point)
 
"To Perl, or not to Perl, that is the kvetching." ~Larry Wall

c_m
Neuling
Neuling
Beiträge: 3
Registriert: 3. Mai 2010 18:07

Re: Second assignment now available

Beitrag von c_m »

In the tests to task 6 you proposed there is a check, if the parse-function returns a (list ...) construct.
Is this even possible to achieve?
The parse-function is supposed to return just F1WAE elements, but as I see it,
we are not able to add the list-type to F1WAE, because it is a build-in type.

Is there anything I'm missing here?
Thanks.

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

Re: Second assignment now available

Beitrag von sewe »

olg hat geschrieben:Are we supposed to follow this definition (i.e., fib(0) = 1) of the fibonacci numbers, or is this an error in your tests?
Yes, please follow our definition of the fibonacci numbers: fib(0) = 1. That the whole sequence is shifted by one doesn't make a huge difference anyway.
c_m hat geschrieben:In the tests to task 6 you proposed there is a check, if the parse-function returns a (list ...) construct.
Is this even possible to achieve?
The parse-function is supposed to return just F1WAE elements, but as I see it,
we are not able to add the list-type to F1WAE, because it is a build-in type.

Is there anything I'm missing here?
Maybe. Can you please quote a specific test case. (I've got two possible interpretations in my mind right now as to what you are missing.)

c_m
Neuling
Neuling
Beiträge: 3
Registriert: 3. Mai 2010 18:07

Re: Second assignment now available

Beitrag von c_m »

sewe hat geschrieben:
c_m hat geschrieben:In the tests to task 6 you proposed there is a check, if the parse-function returns a (list ...) construct.
Is this even possible to achieve?
The parse-function is supposed to return just F1WAE elements, but as I see it,
we are not able to add the list-type to F1WAE, because it is a build-in type.

Is there anything I'm missing here?
Maybe. Can you please quote a specific test case. (I've got two possible interpretations in my mind right now as to what you are missing.)
I'm thinking of:

Code: Alles auswählen

(test (parse '{f 1 2}) (app 'f (list (num 1) (num 2))))
In this example you expect our parse-method to return a (list (num 1) (num 2)), but this would mean, we would have to add the list-element to F1WAE.
But I think this is impossible, because list is a built-in function. We could add a mylist to F1WAE, but with this parse could at most return a mylist-element and still no list.

I hope you can see, what I mean.
Thanks.

Benutzeravatar
olg
Sonntagsinformatiker
Sonntagsinformatiker
Beiträge: 297
Registriert: 1. Okt 2008 19:24

Re: Second assignment now available

Beitrag von olg »

c_m hat geschrieben: [...]
but this would mean, we would have to add the list-element to F1WAE.
But I think this is impossible, because list is a built-in function. We could add a mylist to F1WAE, but with this parse could at most return a mylist-element and still no list.
The list type is available in the F1WAE definition, as is the type number. In our implementation, we do use the list type and did not encounter problems regarding this (or other) test case(s).
Remember that you return a list within the function application node only, and not the list itself.
"To Perl, or not to Perl, that is the kvetching." ~Larry Wall

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

Re: Second assignment now available

Beitrag von sewe »

c_m hat geschrieben:I'm thinking of:

Code: Alles auswählen

(test (parse '{f 1 2}) (app 'f (list (num 1) (num 2))))
In this example you expect our parse-method to return a (list (num 1) (num 2)), but this would mean, we would have to add the list-element to F1WAE.
OK, I can see your problem now: The thing is that parse converts only (sub)expressions to FWAEs. But in an expression like {f 1 2} the 1 2 is not a subexpression; the 1 and 2 are subexpressions (which parse to (num 1) and (num 2), respectively).

qveXx
Mausschubser
Mausschubser
Beiträge: 64
Registriert: 2. Dez 2005 19:02

Re: Second assignment now available

Beitrag von qveXx »

Mal ne Frage zu Task 4:
'(1 . 4) --> (list 1 '. 4) : funktioniert
(list 1 '. 4) --> read: illegal use of "."
(list 1 '\. 4) --> '(1 |.| 4) != '(1 . 4)

Hab gelesen, dass es Probleme mit "." und DrRacket geben soll, aber wie umgehe ich dies?

Weishaupt
Windoof-User
Windoof-User
Beiträge: 37
Registriert: 7. Okt 2009 20:20

Re: Second assignment now available

Beitrag von Weishaupt »

qveXx hat geschrieben:Hab gelesen, dass es Probleme mit "." und DrRacket geben soll, aber wie umgehe ich dies?
I didn't experience any problems with DrRacket and the ".".

qveXx
Mausschubser
Mausschubser
Beiträge: 64
Registriert: 2. Dez 2005 19:02

Re: Second assignment now available

Beitrag von qveXx »

So why the problem appears in my case?
Using DrRacket 5.2.1 and the exercise file with #lang plai, Windows 64bit Version.

(list a '. b) throws the error.

Is there a way using variables with '(a . b)?
With '(a . b), a and b are used as symbols but the "." works here ...

Osterlaus
BSc Spammer
BSc Spammer
Beiträge: 1263
Registriert: 23. Aug 2007 12:46
Wohnort: DA

Re: Second assignment now available

Beitrag von Osterlaus »

I also had some problems with dots appearing in lists, but only in the first assignment. So, why do you want to use a dot anywhere in the fourth task? (cons a b) will give you (a . b), whereever this strange dot comes from....

qveXx
Mausschubser
Mausschubser
Beiträge: 64
Registriert: 2. Dez 2005 19:02

Re: Second assignment now available

Beitrag von qveXx »

When I use (list a '%. b) it works, but combines a list with %. .

I'm using now '_ as combine symbol -> '((1 _ 4) (2 _ 5) (3 _ 6))
The test is bad, because the test expects the list '((1 . 4) (2 . 5) (3 . 6)), but well, don't want to spent too much time on a problem, which just seems to appear in my case and fine for others ;-)

qveXx
Mausschubser
Mausschubser
Beiträge: 64
Registriert: 2. Dez 2005 19:02

Re: Second assignment now available

Beitrag von qveXx »

Osterlaus hat geschrieben:I also had some problems with dots appearing in lists, but only in the first assignment. So, why do you want to use a dot anywhere in the fourth task? (cons a b) will give you (a . b), whereever this strange dot comes from....
cool, (cons a b) brings me the (a . b) without needing to add the "." to the list, (list a b) just (a b).

Thank you very much. Hoping this is not a part of the solution, which is not allowed discussing here :)

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

Re: Second assignment now available

Beitrag von sewe »

qveXx hat geschrieben:
Osterlaus hat geschrieben:I also had some problems with dots appearing in lists, but only in the first assignment. So, why do you want to use a dot anywhere in the fourth task? (cons a b) will give you (a . b), whereever this strange dot comes from....
cool, (cons a b) brings me the (a . b) without needing to add the "." to the list, (list a b) just (a b).
Sorry for not jumping into the discussion earlier, but it seems you have solved the problem yourself already.

Anyways, here's just a bit of background: In ancient times, one of the core implementation concepts of Lisp (Scheme's ancestor) was the so-called cons cell. (BTW, Wikipedia explains this nicely: http://en.wikipedia.org/wiki/Cons) This cell was simply a (36-bit!) word, which contained two (almost) halfwords, accessed by the CAR (Contents of the Address part of Register) and CDR (Contents of the Decrement part of Register) machine instructions, respectively. You could put anything into either halfword, turning the cons cell into a pair, written (lhs . rhs). If, however, the right-hand side represented a list, then so did the (head . tail) cons cell, which would then print as (list head tail...).

And, of course, you would construct a cons cell like (lhs . rhs) simply by (cons lhs rhs).

Osterlaus
BSc Spammer
BSc Spammer
Beiträge: 1263
Registriert: 23. Aug 2007 12:46
Wohnort: DA

Re: Second assignment now available

Beitrag von Osterlaus »

qveXx hat geschrieben:
Osterlaus hat geschrieben:I also had some problems with dots appearing in lists, but only in the first assignment. So, why do you want to use a dot anywhere in the fourth task? (cons a b) will give you (a . b), whereever this strange dot comes from....
cool, (cons a b) brings me the (a . b) without needing to add the "." to the list, (list a b) just (a b).

Thank you very much. Hoping this is not a part of the solution, which is not allowed discussing here :)
Yeeeah, you're happy about this - but it caused me such a headache in the first exercise that there WAS a dot where I don't want to have one.... ;)

Antworten

Zurück zu „Archiv“