Fifth assignment now available

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

Fifth assignment now available

Beitrag von sewe »

Please update your working copy.

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

Re: Fifth assignment now available

Beitrag von Maradatscha »

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

I used guards in task1 and task2, all Testcases work.

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

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

Re: Fifth assignment now available

Beitrag von mantra »

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
Sonntagsinformatiker
Beiträge: 224
Registriert: 3. Nov 2005 19:12
Kontaktdaten:

Re: Fifth assignment now available

Beitrag von BastiS »

One question concerning task 4:
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.

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

Re: Fifth assignment now available

Beitrag von mantra »

Because x^0 = 1

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

Re: Fifth assignment now available

Beitrag von Nori »

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

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

Re: Fifth assignment now available

Beitrag von sewe »

@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
Mausschubser
Beiträge: 80
Registriert: 14. Okt 2008 20:04

Re: Fifth assignment now available

Beitrag von tzeenie »

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?

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

Re: Fifth assignment now available

Beitrag von sewe »

@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
Mausschubser
Beiträge: 80
Registriert: 14. Okt 2008 20:04

Re: Fifth assignment now available

Beitrag von tzeenie »

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. :P

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

Re: Fifth assignment now available

Beitrag von sproksch »

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...

Gesperrt

Zurück zu „Archiv“