<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">I think I found the solution.<br>
<br>
I still have to design the render function.<br>
<br>
I have this : <br>
<br>
<br>
; niet grafische constanten.<br>
<br>
(define lengte-werkblad 200)<br>
(define breedte-werkblad 1000)<br>
(define move-animal 3)<br>
(define move-gauge 0.1)<br>
<br>
; grafische constanten<br>
<br>
(define kat .)<br>
(define cham .)<br>
(define workspace (empty-scene breedte-werkblad lengte-werkblad))<br>
(define gauge-omtrek (rectangle 1000 20 "outline" "black"))<br>
<br>
<br>
; berekende constanten<br>
(define correctie-cat ( / (image-width kat)2))<br>
(define ondergrens-cat ( - 0 correctie-cat))<br>
(define bovengrens-cat ( + breedte-werkblad correctie-cat))<br>
<br>
(define correctie-cham ( / (image-width cham)2))<br>
(define ondergrens-cham ( - 0 correctie-cham))<br>
(define bovengrens-cham ( + breedte-werkblad correctie-cham))<br>
<br>
; Te gebruiken structs<br>
<br>
; Design a world program that works with both cats and chameleons:
<br>
; A VAnimal is either<br>
; – a VCat<br>
; – a VCham<br>
<br>
(define-struct Vcat (Xcat Hcat Richting))<br>
; Vcat = (make-editor Number Number)<br>
; interp. (make-editor x h r) where x is the x-coordinate of the
cat and h is the happiness of the cat and r the way the cat walks.<br>
; make-editor Number Number String -> Vcat<br>
; Vcat-Xcat Editor -> Number<br>
; Vcat-Hcat Editor -> Number<br>
; Vcat-Richting -> String<br>
; Vcat? Editor Any -> Boolean<br>
<br>
<br>
(define-struct Vcham (Xcham Hcham Richting))<br>
; Vcham = (make-editor Number Number)<br>
; interp. (make-editor x h r) where x is the x-coordinate of the
cham and h is the happiness of the cham and r the way the cham
walks.<br>
; make-editor Number Number String -> Vcat<br>
; Vcham-Xcham Editor -> Number<br>
; Vcham-Hcham Editor -> Number<br>
; Vcham-Richting -> String<br>
; Vcham? Editor Any -> Boolean<br>
<br>
<br>
; Vcham -> Vcham<br>
; Function who makes the image move to the left or turn to the
right<br>
(check-expect (links-of-draaien-cham (make-Vcham 20 100 "left"))
(make-Vcham 17 99.9 "left"))<br>
(check-expect (links-of-draaien-cham (make-Vcham -39 100 "left"))
(make-Vcham -39 99.9 "right"))<br>
(check-expect (links-of-draaien-cham (make-Vcham 1037 100 "left"))
(make-Vcham 1034 99.9 "left"))<br>
(define (links-of-draaien-cham s)<br>
(if ( < (Vcham-Xcham Vcham) ondergrens-cham)<br>
(make-Vcham (Vcham-Xcham s) (- (Vcham-Hcham s) move-gauge)
"right")<br>
(make-Vcham (- (Vcham-Xcham s) move-animal) (- (Vcham-Hcham s)
move-gauge) "left")))<br>
<br>
<br>
<br>
; Vcat -> Vcat<br>
; Function who makes the image move to the left or turn to the
right<br>
(check-expect (links-of-draaien-cat (make-Vcat 20 100 "left"))
(make-Vcat 17 99.9 "left"))<br>
(check-expect (links-of-draaien-cat (make-Vcat -39 100 "left"))
(make-Vcat -39 99.9 "right"))<br>
(check-expect (links-of-draaien-cat (make-Vcat 1037 100 "left"))
(make-Vcat 1034 99.9 "left"))<br>
(define (links-of-draaien-cat s)<br>
(if ( < (Vcat-Xcat Vcat) ondergrens-cat)<br>
(make-Vcat (Vcat-Xcat s) (- (Vcat-Hcat s) move-gauge)
"right")<br>
(make-Vcat (- (Vcat-Xcat s) move-animal) (- (Vcat-Hcat s)
move-gauge) "left"))<br>
)<br>
<br>
; Vcham -> Vcham<br>
; Function who makes the image move to the right or turn to the
left<br>
(check-expect (rechts-of-draaien-cham (make-Vcham 20 100 "right"))
(make-Vcham 23 99.9 "right"))<br>
(check-expect (rechts-of-draaien-cham (make-Vcham -39 100
"right")) (make-Vcham -36 99.9 "right"))<br>
(check-expect (rechts-of-draaien-cham (make-Vcham 1040 100
"right")) (make-Vcham 1040 99.9 "left"))<br>
(define (rechts-of-draaien-cham s)<br>
(if ( > (Vcham-Xcham Vcham) bovengrens-cham)<br>
(make-Vcham (Vcham-Xcham s) (- (Vcham-Hcham s) move-gauge)
"left")<br>
(make-Vcham (+ (Vcham-Xcham s) move-animal) (- (Vcham-Hcham s)
move-gauge) "right")))<br>
<br>
<br>
; Vcat -> Vcat<br>
; Function who makes the image move to the right or turn to the
left<br>
(check-expect (rechts-of-draaien-cat (make-Vcat 20 100 "right"))
(make-Vcat 23 99.9 "right"))<br>
(check-expect (rechts-of-draaien-cat (make-Vcat -39 100 "right"))
(make-Vcat -36 99.9 "right"))<br>
(check-expect (rechts-of-draaien-cat (make-Vcat 1040 100 "right"))
(make-Vcat 1040 99.9 "left"))<br>
(define (rechts-of-draaien-cat s)<br>
(if ( > (Vcat-Xcat Vcat) bovengrens-cat)<br>
(make-Vcat (Vcat-Xcat s) (- (Vcat-Hcat s) move-gauge) "left")<br>
(make-Vcat (+ (Vcat-Xcat s) move-animal) (- (Vcat-Hcat s)
move-gauge) "right"))<br>
)<br>
<br>
; Vanimal -> Vanimal<br>
; Function which change the world on clock ticks.<br>
; On every tick the X-coordinate changes 3 pixels and the
happiness decrease with 0.1.<br>
(define (tock s)<br>
(cond <br>
[(Vcat? s)(if(equal? (Vcat-Richting s) "left")
(links-of-draaien-cat Vcat) (rechts-of-draaien-cat Vcat))]<br>
[(Vcham? s) (if(equal? (Vcham-Richting s) "left")
(links-of-draaien-cham Vcham) (rechts-of-draaien-cat Vcham))]<br>
))<br>
<br>
(define (render s)s)<br>
<br>
(define (main s)<br>
(cond <br>
[(Vcat? s) (big-bang s (check-with Vcat?) (on-tick tock)
(on-draw render) )]<br>
[(Vcham? s) (big-bang s (check-with Vcham?) (on-tick tock)
(on-draw render) )]<br>
))<br>
<br>
(main (make-Vcat 12 100 "left"))<br>
<br>
Is this better ?<br>
<br>
Roelof<br>
<br>
<br>
Op 30-6-2012 9:03, Roelof Wobben schreef:<br>
</div>
<blockquote cite="mid:4FEEA4CD.4010808@home.nl" type="cite">
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
<div class="moz-cite-prefix">Op 30-6-2012 1:38, Neil Van Dyke
schreef:<br>
</div>
<blockquote cite="mid:4FEE3C65.6070809@neilvandyke.org"
type="cite">Stephen Bloch wrote at 06/29/2012 06:01 PM: <br>
<blockquote type="cite">Either you introduce this stuff much
better than I do, or your students are much sharper. <br>
</blockquote>
<br>
For the possible benefit of any students reading, I think
someone say it, rather than leave it implied: Or the difference
could be an isolated effect of, say, some subtle difference in
how one concept was first introduced in their respective
educations, not a reflection on the instruction or students
overall. <br>
<br>
Aside: I think students are much the same everywhere, and most
all students have potential to be good at this stuff. But
learning this stuff well requires a lot of work, and I think
students generally do need to have sufficient sense that they're
``sharp,'' so that they stick with it and put in the necessary
work. Or, there is another category of person, who sees
themself as slow but determined; that will also lead to learning
the stuff, if the self image gets them to put in the necessary
work. (However, the ones who are self-assured and yet who don't
do the learning work... they are doomed to be dim and to have
few job options other than some kind of politician.) <br>
<br>
Neil V. <br>
<br>
____________________ <br>
Racket Users list: <br>
<a moz-do-not-send="true" class="moz-txt-link-freetext"
href="http://lists.racket-lang.org/users">http://lists.racket-lang.org/users</a>
<br>
<br>
</blockquote>
<br>
<br>
Im rereading the chapter and I think I found a piece of the
puzzle. <br>
<br>
In the chapter there is a mention of this : <br>
<br>
<table class="RktBlk" cellspacing="0">
<tbody>
<tr>
<td><span class="RktCmt">;</span><span class="RktCmt"> </span><span
class="RktCmt">A </span><a moz-do-not-send="true"
name="(tech._mix._sig)"></a><span style="font-style:
italic;">SIGS</span><span class="RktCmt"> (short for </span><span
class="RktCmt">“</span><span class="RktCmt">space
invader game state</span><span class="RktCmt">”</span><span
class="RktCmt">) is one of: </span></td>
</tr>
<tr>
<td><span class="RktCmt">;</span><span class="RktCmt"> </span><span
class="RktCmt">–</span><span class="RktCmt"> </span><span
class="RktPn">(</span><span class="RktSym">make-aim</span><span
class="stt"> </span><a moz-do-not-send="true"
class="techoutside" href="#%28tech._mix._ufo%29"
pltdoc="x"><span class="techinside">UFO</span></a><span
class="stt"> </span><a moz-do-not-send="true"
class="techoutside" href="#%28tech._mix._tank%29"
pltdoc="x"><span class="techinside">Tank</span></a><span
class="RktPn">)</span></td>
</tr>
<tr>
<td><span class="RktCmt">;</span><span class="RktCmt"> </span><span
class="RktCmt">–</span><span class="RktCmt"> </span><span
class="RktPn">(</span><span class="RktSym">make-fired</span><span
class="stt"> </span><a moz-do-not-send="true"
class="techoutside" href="#%28tech._mix._ufo%29"
pltdoc="x"><span class="techinside">UFO</span></a><span
class="stt"> </span><a moz-do-not-send="true"
class="techoutside" href="#%28tech._mix._tank%29"
pltdoc="x"><span class="techinside">Tank</span></a><span
class="stt"> </span><a moz-do-not-send="true"
class="techoutside" href="#%28tech._mix._missile%29"
pltdoc="x"><span class="techinside">Missile</span></a><span
class="RktPn">)</span></td>
</tr>
</tbody>
</table>
<br>
<br>
I can do the same for my problem.<br>
<br>
; A Vanimal is one of :<br>
; - (make-Vcat ( x happiness) <br>
; (make-Vcham ( x happiness) <br>
<br>
So Vanimal is not a struct but strictly a name.<br>
<br>
Am I on the right track. <br>
<br>
Roelof<br>
<br>
<br>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">____________________
Racket Users list:
<a class="moz-txt-link-freetext" href="http://lists.racket-lang.org/users">http://lists.racket-lang.org/users</a>
</pre>
</blockquote>
<br>
<br>
</body>
</html>