Hello Everyone,<br><br> i a a newbie who is trying to find his way through the "jungle of programming" by using the HTDP map. This time in sectio-6 i ran into a problem in understanding the "crucial ways" the map represents.
<br><br>I have solved the "pre-hangman problems" (i.e. ex 6.7.1 - .2 & .3) . both programes execute without any error, but when i try to play "hangman" game using both of them i get an error:<br>-------------------------
<br>ERROR:<br><br>The teachpack file /usr/lib/plt/teachpack/htdp/hangman.ss did not load properly.<br>teachpack: export of stop from "/usr/lib/plt/teachpack/htdp/hangman.ss" conflicts with already existing definitions
<br>------------------------------------<br><br>I have drscheme version209 running on debian "sarge".<br><br>may you help me?<br><br>;; -------------here is the programme-----------<br><br>(define-struct word (s1 s2 s3))
<br>;;a word is a structure: (make-word s s s), where s s & s are symbols.<br><br>#|<br>;; reveal : word word letter -> 3l-word<br>;; to produce a word dependent on & from given 3 different arguments<br>;; (define (reveal chosen-word status-word letter-guessed)..)
<br><br>;; examples<br>(reveal (make-word 't'e'a) (make-word '_'e'_) 'u)<br>;; expected value<br>(make-word '_'e'_)<br><br>(reveal (make-word 't'e'a) (make-word 't'_'_) 'a)<br>;; expected value<br>(make-word 't_'a)<br><br>
(reveal (make-word 'a'l'l) (make-word '_'_'_) 'l)<br>;; expected value<br>(make-word '_'l'l) <br><br> TEMPLATE:<br>(define (process-reveal word1 word2 letter)<br> ...(word-s1 word1)...(word-s1 word2)...<br> ...(word-s2 word1)...(word-s2 word2)...
<br> ...(word-s3 word1)...(word-s3 word2)...)<br><br>|#<br><br>(define (reveal word-chosen word-status a-letter)<br> (cond<br> [(test-all3 word-chosen word-status a-letter) (create-full word-chosen word-status a-letter)]
<br> [(test-12 word-chosen word-status a-letter) (create-12 word-chosen word-status a-letter)]<br> [(test-23 word-chosen word-status a-letter) (create-23 word-chosen word-status a-letter)]<br> [(test-13 word-chosen word-status a-letter) (create-13 word-chosen word-status a-letter)]
<br> [(symbol=? (word-s1 word-chosen) a-letter) (create-word-s1 word-chosen word-status a-letter)]<br> [(symbol=? (word-s2 word-chosen) a-letter) (create-word-s2 word-chosen word-status a-letter)]<br> [(symbol=? (word-s3 word-chosen) a-letter) (create-word-s3 word-chosen word-status a-letter)]
<br> [else word-status]))<br><br><br>(define (test-all3 word1 word2 a-letter)<br> (and (symbol=? (word-s1 word1) a-letter)<br> (symbol=? (word-s2 word1) a-letter)<br> (symbol=? (word-s3 word1) a-letter)))<br>
<br>(define (create-full word1 word2 a-letter)<br> (make-word a-letter<br> a-letter <br> a-letter))<br> <br>(define (test-12 word1 word2 a-letter)<br> (and (symbol=? (word-s1 word1) a-letter)<br>
(symbol=? (word-s2 word1) a-letter)))<br><br>(define (test-23 word1 word2 a-letter)<br> (and (symbol=? (word-s3 word1) a-letter)<br> (symbol=? (word-s2 word1) a-letter)))<br><br>(define (test-13 word1 word2 a-letter)
<br> (and (symbol=? (word-s1 word1) a-letter)<br> (symbol=? (word-s3 word1) a-letter)))<br><br>(define (create-12 word-chosen word-status a-letter)<br> (make-word a-letter<br> a-letter<br> (word-s3 word-status)))
<br><br>(define (create-23 word-chosen word-status a-letter)<br> (make-word (word-s1 word-status)<br> a-letter<br> a-letter))<br><br>(define (create-13 word-chosen word-status a-letter)<br> (make-word a-letter
<br> (word-s2 word-status)<br> a-letter))<br><br><br>(define (create-word-s1 word-chosen word-status a-letter)<br> (make-word a-letter<br> (word-s2 word-status)<br> (word-s3 word-status)))
<br><br>(define (create-word-s2 word-chosen word-status a-letter)<br> (make-word (word-s1 word-status)<br> a-letter<br> (word-s3 word-status)))<br><br>(define (create-word-s3 word-chosen word-status a-letter)
<br> (make-word (word-s1 word-status)<br> (word-s2 word-status)<br> a-letter))<br>#|<br>;; tests<br><br>(reveal (make-word 't'e'a) (make-word '_'e'_) 'u)<br>;; expected value = <br>(make-word '_'e'_)
<br><br>(reveal (make-word 't'e'a) (make-word 't'_'_) 'a)<br>;; expected value = (make-word 't'_'a)<br><br>(reveal (make-word 'a'l'l) (make-word '_'_'_) 'l)<br>;; expected value = (make-word '_'l'l) <br>(reveal (make-word 'l'l'l) (make-word '_'_'_) 'l)
<br>;; expected value = (make-word 'l'l'l)<br>(reveal (make-word 'a'l'l) (make-word '_'_'_) 'p)<br>;; expected value = (make-word '_'_'_)<br>|#<br>;;-----------------------------------------------------------------------------------------
<br><br><br>;; draw-next-part : symbol -> true<br>;; to draw the given symbol on the canvs in "hangman" style<br><br>(define START (make-posn 10 10))<br>(define END-1 (make-posn 50 10))<br>(define END-2 (make-posn (posn-x END-1) 20))
<br>(define HEAD-RADIUS 10)<br>(define HEAD-DIA (* 2 HEAD-RADIUS))<br>(define HEIGHT 50)<br><br><br><br>(define (draw-next-part a-symbol)<br> (cond<br> [(symbol=? 'right-leg a-symbol) (draw-right-leg a-symbol)]<br> [(symbol=? 'left-leg a-symbol) (draw-left-leg a-symbol)]
<br> [(symbol=? 'left-arm a-symbol) (draw-left-arm a-symbol)]<br> [(symbol=? 'right-arm a-symbol) (draw-right-arm a-symbol)]<br> [(symbol=? 'body a-symbol) (draw-body a-symbol)]<br> [(symbol=? 'head a-symbol) (draw-head a-symbol)]
<br> [(symbol=? 'noose a-symbol) (draw-noose a-symbol)]<br> [else 'No-match]))<br><br>(define (draw-noose a-sym)<br> (and (draw-solid-line START END-1)<br> (draw-solid-line END-1 END-2))) <br><br>(define (draw-head a-sym)
<br> (draw-circle (make-posn (posn-x END-2)<br> (+ (posn-y END-2) HEAD-RADIUS)) HEAD-RADIUS 'black))<br><br>(define (draw-body a-sym)<br> (draw-solid-line (make-posn (posn-x END-2)<br> (+ (posn-y END-2) HEAD-DIA))
<br> (make-posn (posn-x END-2)<br> (+ (posn-y END-2) HEAD-DIA HEIGHT)) 'black))<br><br>(define (draw-right-arm a-sym)<br> (draw-solid-line (make-posn (posn-x END-2)<br> (+ (posn-y END-2) HEAD-DIA HEAD-DIA))
<br> (make-posn (+ (posn-x END-2) (- HEIGHT HEAD-DIA))<br> (+ (posn-y END-2) HEAD-DIA))))<br><br>(define (draw-left-arm a-sym)<br> (draw-solid-line (make-posn (posn-x END-2)
<br> (+ (posn-y END-2) HEAD-DIA HEAD-DIA))<br> (make-posn (- (posn-x END-2) (- HEIGHT HEAD-DIA))<br> (+ (posn-y END-2) HEAD-DIA))))<br><br>(define (draw-right-leg a-symbol)
<br> (draw-solid-line (make-posn (posn-x END-2)<br> (+ (posn-y END-2) HEAD-DIA HEIGHT))<br> (make-posn (+ (posn-x END-2) (- HEIGHT HEAD-RADIUS))<br> (+ (posn-y END-2) (+ HEIGHT HEAD-DIA HEAD-DIA)))))
<br><br>(define (draw-left-leg a-symbol)<br> (draw-solid-line (make-posn (posn-x END-2)<br> (+ (posn-y END-2) HEAD-DIA HEIGHT))<br> (make-posn (- (posn-x END-2) (- HEIGHT HEAD-DIA))
<br> (+ (posn-y END-2) HEIGHT HEAD-DIA HEAD-DIA))))<br> <br><br>#| <br> creation of this HANGMAN was inspired from TRAFFIC-LIGHT (fig. 8) which is an an excellent <br>example of using 'global definitions' for specifying & computing constants.
<br>and what? every part of the HANGMAN-body is in perfect sync with the other.<br>(draw-noose 'kl)<br>(draw-head 'lk)<br>(draw-body 'l)<br>(draw-right-arm 'l)<br>(draw-left-arm 'l)<br>(draw-right-leg 'l)<br>(draw-left-leg 'l) |#
<br><br>;; test<br><br>(hangman make-word reveal draw-next-part)<br><br>;;------------ end of programme --------------------------------------<br>