## Fifth assignment now available

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

### Fifth assignment now available

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

### Re: Fifth assignment now available

My Implementation of combine2 works with Task5. Could anyone give me a hint what I'm doing wrong (right) here?

edit: me = stupid copy paste mistakes, its not working anymore, found the problem

mantra
Computerversteher
Beiträge: 385
Registriert: 23. Okt 2005 23:56

### Re: Fifth assignment now available

Maradatscha hat geschrieben:edit: me = stupid copy paste mistakes, its not working anymore, found the problem
Hehe, guess I made the same mistake

I got stuck at task 6 enforcing eager evaluation. I'm not quite sure, whether I employ 'seq' the right way - however, it makes sense to me. Still, the test cases don't seem to care, they still don't fail. Any hints on that?

*edit: it's task 7.1, and I figured it out
Zuletzt geändert von mantra am 1. Jun 2009 17:16, insgesamt 1-mal geändert.

BastiS
Sonntagsinformatiker
Beiträge: 224
Registriert: 3. Nov 2005 19:12
Kontaktdaten:

### Re: Fifth assignment now available

Why does 1 have a prime factor in 2, 3, 5?
IMHO the one should not be in the result list.

Edit: I see, it's easier to solve with the leading 1 but I don't really understand why it should be in the list.

mantra
Computerversteher
Beiträge: 385
Registriert: 23. Okt 2005 23:56

### Re: Fifth assignment now available

Because x^0 = 1

Nori
Erstie
Beiträge: 22
Registriert: 15. Nov 2006 17:40
Kontaktdaten:

### Re: Fifth assignment now available

In task 7.1, when interpreting "if" should the "then-clause" and the "else-clause" also be eagerly evaluated, or just the "conditional-clause"?

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

### Re: Fifth assignment now available

@Nori: Hm, this is a hard one, if one doesn't want to spoil the exercise. So let me answer with a few questions: Who forces the evaluation of cond? And why? And finally, when would you force evaluation of lhs and rhs? And do you really have to?

tzeenie
Mausschubser
Beiträge: 80
Registriert: 14. Okt 2008 20:04

### Re: Fifth assignment now available

I just noticed that the interpreter in the fifth assignment does not implement static scope - am I correct? This should not evaluate to NumV 9 with static scope, but it does:

Code: Alles auswählen

interp (With "x" (Num 5) (App (Fun "z" (Add (Id "x") (Num 4))) (Id "x"))) []

So I assume it's ok if the modified interpreter keeps this behaviour?

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

### Re: Fifth assignment now available

@tzeenie: Why shouldn't it evaluate to NumV 9? The Fun was defined in a scope where x = 5, so it returns 5 + 4. This is exactly what static scoping does, although your example would behave exactly the same with dynamic scoping. A better example would be the following:

Code: Alles auswählen

interp
(With "x" (Num 5)
(With "f" (Fun "z" (Add (Id "x") (Num 4)))
(With "x" (Num 1)
(App (Id "f") (Num 2)))))
Since f was defined in a scope where x = 5, it returns 5 + 4, even though it was called in a scope where x = 1. (The argument of 2 doesn't have any effect, as the idenfier z is not used within the function's body.) I hope this clarifies things a bit.

tzeenie
Mausschubser
Beiträge: 80
Registriert: 14. Okt 2008 20:04

### Re: Fifth assignment now available

sewe hat geschrieben:I hope this clarifies things a bit.
Thanks, yes, a very helpful post, as usual! I think I've understood it now, it's quite confusing - to me relying on an variable defined "outside" of a function seemed to be allowing side-effects. But our identifiers are not variables, they are immutable in their scope (although they can be "overwritten" in a nested scope), which is fine as long as they are immutable towards the function definition, so the interpreter's behaviour is just fine.

sproksch
Computerversteher
Beiträge: 346
Registriert: 15. Apr 2004 17:56

### Re: Fifth assignment now available

Suggestion: The "new exercise is available" threads should be closed immediately after posting

All questions concerning the new execise are mixed up in this thread... if closed, the questioners are forced to create a new thread and therefore all task specific questions are grouped together...