Hangman with DrRacket v5.0.1

244 views
Skip to first unread message

RacketEveryday

unread,
Sep 20, 2010, 10:04:37 PM9/20/10
to Study-HTDP
When I fired up hangman under DrRacket v5.0.1, I ran through this
error message:

hangman: expected words to be structures with three fields, found 4
fields

I defined my word to be
(define-struct word (c1 c2 c3))
which should be perfectly acceptable to the main program. So I dig
around a little bit, and found out that, for some reason, they added
one extra field to the structure created using define-struct. The
length of the vector created using struct->vector is 5 for our word
structure, instead of 4 as expected by hangman teachpack.

In order to run hangman successfully, one need to modify Racket/
collects/htdp/hangman.rkt, go to line 253, at position 51, hit
backspace, and type 5. Save the file, and compile this file using mzc.

By the way, how can I compile things from inside DrRacket?

Dave

unread,
Oct 30, 2010, 11:56:33 PM10/30/10
to Study-HTDP
I'm getting the same error, but am not yet convinced I haven't done
anything wrong.
I've recently returned to this book after a 2 year break and don't
recall this one causing me any trouble.

I currently have

; a word is a structure
(define-struct word (w1 w2 w3))
;where 1 2 and 3 are symbols; 'a to 'z and '_


#|
(define (fun-for-word a-word)
... (word-1 a-word) ...
... (word-2 a-word) ...
... (word-3 a-word) ...)
|#



;draw-next-part symbol -> effect on canvas
;to consume a symbol representing a body part and draw the
corresponding part on the canvas
(define (draw-next-part part)
(cond
((symbol=? part 'left-leg)
(draw-solid-line (make-posn 100 300) (make-posn 180 380)))

((symbol=? part 'right-leg)
(draw-solid-line (make-posn 100 300) (make-posn 20 380)))

((symbol=? part 'left-arm)
(draw-solid-line (make-posn 100 150) (make-posn 180 230)))

((symbol=? part 'right-arm)
(draw-solid-line (make-posn 100 150) (make-posn 20 230)))

((symbol=? part 'body)
(draw-solid-line (make-posn 100 150) (make-posn 100 300)))

((symbol=? part 'head)
(and (and (and (and (and (draw-a-circle (make-circle (make-posn
100 100) 50 'red)) (draw-solid-line (make-posn 85 75) (make-posn 75
85))) (draw-solid-line (make-posn 75 75) (make-posn 85 85))) (draw-
solid-line (make-posn 125 75) (make-posn 115 85))) (draw-solid-line
(make-posn 125 85) (make-posn 115 75))) (draw-a-circle (make-circle
(make-posn 100 125) 10 'red))))

((symbol=? part 'noose)
(and (draw-solid-line (make-posn 1 10) (make-posn 85 10)) (draw-
solid-line (make-posn 85 10) (make-posn 85 50))))

(else 'noSuchPart)))


;reveal word word symbol -> word
;reveal consumes a chosen word, a status word and a guess letter and
updates the status word if the chosen word contains the guess letter
(1 letter symbol)
(define (reveal chosen status guess)
(make-word (match-word (word-w1 chosen) (word-w1 status) guess)
(match-word (word-w2 chosen) (word-w2 status) guess) (match-word (word-
w3 chosen) (word-w3 status) guess)))

;match-word symbol symbol symbol -> symbol
;match-word consumes a chosen letter, a status letter and a guess
letter. if the guess letter matches the chosen letter it outputs the
guess letter otherwise it outputs the status letter.
(define (match-word chosen status guess)
(cond
((symbol=? guess chosen) chosen)
(else status)))


The functions passed any tests I did though ,

(reveal (make-word 'c 'a 't) (make-word '_ '_ '_) 'c)

gives:

(make-word 'c '_ '_)

so I guess I'll call it done? The only thing that doesn't work is:

(hangman make-word reveal draw-next-part)

Which gives the error:

hangman: expected words to be structures with three fields, found 4
fields

Just hope I'm not missing anything.

Luke Jordan

unread,
Oct 31, 2010, 12:23:17 PM10/31/10
to study...@googlegroups.com
Go through it with the stepper and see what it's doing right before the error.  Based on the error msg you're quoting there's somewhere where you have a function that operates on a word structure that is being passed a word structure with an extra argument.  Another way to go is to find for all instances of make-word and look for a make-word call with 4 args rather than 3.  It's probably just a typo somewhere in the code.

Dave

unread,
Nov 2, 2010, 4:30:10 AM11/2/10
to Study-HTDP
Unfortunately stepper just yields

Couldn't find a step matching that criterion.


:(

Luke Jordan

unread,
Nov 2, 2010, 12:11:59 PM11/2/10
to study...@googlegroups.com

That's what happens when there's an error that stops execution. What you're interested in is what is being evaluated just before then (the code that caused execution to stop). By the time a matching criterion can't be found you are post-error. The stepper can't find a matching criterion because an error has stopped the program.

Reply all
Reply to author
Forward
0 new messages