14.1.6

2 views
Skip to first unread message

kenny

unread,
Oct 7, 2010, 10:01:52 AM10/7/10
to Study-HTDP
I am really having trouble with formulating the code to the question.

My code:
(define(proper a-ftn)
(cond
[(and(empty?(child-mother a-ftn))
(empty?(child-father a-ftn)))false]
[(or(symbol=?(child-eyes(child-mother a-ftn))'blue)
(proper(child-father a-ftn)))true]))

I have tried multiple things, including setting the first clause to
just [(empty? a-ftn)false]

I am able to get the program partially working if I change the code
to:
(define(proper a-ftn)
(cond
[(empty? a-ftn)false]
[else(cond
[(symbol=?(child-eyes(child-mother a-ftn))'blue)true]
[else(proper(child-father a-ftn)])]))

I used the family tree supplied by the book, if I test it with gustav,
it gives me true if eva has blue eyes. My problem is that is fred, not
eva has blue eyes I cant seem to get the program to search his tree as
well, it simply reaches carl and bettina, and causes an error.

Any ideas with what I can do, or something I am missing would be
greatly appreciated.

MyOMy Racket

unread,
Oct 7, 2010, 10:15:56 PM10/7/10
to study...@googlegroups.com
Let's try to run the program by hand, and see what will happen. Suppose Eva has gray eyes instead of blue.

(proper (make-child Fred Eva 'Gustav 1988 'brown))
= (cond
[(symbol=? (child-eyes (make-child Carl Bettina 'Eva 1965 'gray)) 'blue) true]
[else (proper Fred)])
= (cond
[(symbol=? 'gray 'blue) true]
[else (proper Fred)])
= (proper Fred)

Now you see where the problem is, yes?

Frodo

2010/10/7 kenny <heg...@yahoo.com>
Message has been deleted
Message has been deleted

kenny

unread,
Oct 8, 2010, 8:13:30 AM10/8/10
to Study-HTDP
I believe I figured it out. Thanks for the help!
Code that works:

(define(proper a-ftn)
(cond
[(or(empty?(child-father a-ftn))
(empty?(child-mother a-ftn))
(empty? a-ftn))false]
[else(cond
[(or(symbol=?(child-eyes(child-mother a-ftn))'blue)
(symbol=?(child-eyes(child-father a-ftn))'blue))
true]
[else(or(proper(child-mother a-ftn))
(proper(child-father a-ftn)))])]))

On Oct 7, 10:15 pm, MyOMy Racket <racketgr...@gmail.com> wrote:
> Let's try to run the program by hand, and see what will happen. Suppose Eva
> has gray eyes instead of blue.
>
> (proper (make-child Fred Eva 'Gustav 1988 'brown))
> = (cond
> [(symbol=? (child-eyes (make-child Carl Bettina 'Eva 1965 'gray)) 'blue)
> true]
> [else (proper Fred)])
> = (cond
> [(symbol=? 'gray 'blue) true]
> [else (proper Fred)])
> = (proper Fred)
>
> Now you see where the problem is, yes?
>
> Frodo
>
> 2010/10/7 kenny <hege...@yahoo.com>

MyOMy Racket

unread,
Oct 11, 2010, 5:31:20 AM10/11/10
to study...@googlegroups.com
You're welcome and congrats!
Reading htdp is like playing a puzzle game. Sometimes it drives you crazy :)

Frodo

2010/10/8 kenny <heg...@yahoo.com>
Reply all
Reply to author
Forward
0 new messages