[racket] why is the comparimng always false

From: Roelof Wobben (r.wobben at home.nl)
Date: Sat Jun 30 04:19:32 EDT 2012

I think I found the solution.

I still have to design the render function.

I have this :


; niet grafische constanten.

(define lengte-werkblad 200)
(define breedte-werkblad 1000)
(define move-animal 3)
(define move-gauge 0.1)

; grafische constanten

(define kat  .)
(define cham .)
(define workspace (empty-scene breedte-werkblad lengte-werkblad))
(define gauge-omtrek (rectangle 1000 20 "outline" "black"))


; berekende constanten
(define correctie-cat ( / (image-width kat)2))
(define ondergrens-cat ( - 0  correctie-cat))
(define bovengrens-cat ( + breedte-werkblad correctie-cat))

(define correctie-cham ( / (image-width cham)2))
(define ondergrens-cham ( - 0  correctie-cham))
(define bovengrens-cham ( + breedte-werkblad correctie-cham))

; Te gebruiken structs

; Design a world program that works with both cats and chameleons:
; A VAnimal is either
; -- a VCat
; -- a VCham

(define-struct Vcat (Xcat Hcat Richting))
; Vcat = (make-editor Number Number)
; 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.
; make-editor Number Number  String -> Vcat
; Vcat-Xcat Editor -> Number
; Vcat-Hcat Editor -> Number
; Vcat-Richting -> String
; Vcat? Editor Any -> Boolean


(define-struct Vcham (Xcham Hcham Richting))
; Vcham = (make-editor Number Number)
; 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.
; make-editor Number Number String  -> Vcat
; Vcham-Xcham Editor -> Number
; Vcham-Hcham Editor -> Number
; Vcham-Richting -> String
; Vcham? Editor Any -> Boolean


; Vcham -> Vcham
; Function who makes the image move to the left or turn to the right
(check-expect (links-of-draaien-cham (make-Vcham 20 100 "left")) 
(make-Vcham 17 99.9 "left"))
(check-expect (links-of-draaien-cham (make-Vcham -39 100 "left")) 
(make-Vcham -39 99.9 "right"))
(check-expect (links-of-draaien-cham (make-Vcham 1037 100 "left")) 
(make-Vcham 1034 99.9 "left"))
(define (links-of-draaien-cham s)
(if ( < (Vcham-Xcham Vcham) ondergrens-cham)
    (make-Vcham  (Vcham-Xcham s)  (- (Vcham-Hcham s) move-gauge) "right")
    (make-Vcham (- (Vcham-Xcham s) move-animal) (- (Vcham-Hcham s) 
move-gauge) "left")))



; Vcat -> Vcat
; Function who makes the image move to the left or turn to the right
(check-expect (links-of-draaien-cat (make-Vcat 20 100 "left")) 
(make-Vcat 17 99.9 "left"))
(check-expect (links-of-draaien-cat (make-Vcat -39 100 "left")) 
(make-Vcat -39 99.9 "right"))
(check-expect (links-of-draaien-cat (make-Vcat 1037 100 "left")) 
(make-Vcat 1034 99.9 "left"))
(define (links-of-draaien-cat s)
(if ( < (Vcat-Xcat Vcat) ondergrens-cat)
    (make-Vcat  (Vcat-Xcat s)  (- (Vcat-Hcat s) move-gauge) "right")
    (make-Vcat (- (Vcat-Xcat s) move-animal) (- (Vcat-Hcat s) 
move-gauge) "left"))
)

; Vcham -> Vcham
; Function who makes the image move to the right or turn to the left
(check-expect (rechts-of-draaien-cham (make-Vcham 20 100 "right")) 
(make-Vcham 23 99.9 "right"))
(check-expect (rechts-of-draaien-cham (make-Vcham -39 100 "right")) 
(make-Vcham -36 99.9 "right"))
(check-expect (rechts-of-draaien-cham (make-Vcham 1040 100 "right")) 
(make-Vcham 1040 99.9 "left"))
(define (rechts-of-draaien-cham s)
(if ( > (Vcham-Xcham Vcham) bovengrens-cham)
    (make-Vcham  (Vcham-Xcham s)  (- (Vcham-Hcham s) move-gauge) "left")
    (make-Vcham (+ (Vcham-Xcham s) move-animal) (- (Vcham-Hcham s) 
move-gauge) "right")))


; Vcat -> Vcat
; Function who makes the image move to the right or turn to the left
(check-expect (rechts-of-draaien-cat (make-Vcat 20 100 "right")) 
(make-Vcat 23 99.9 "right"))
(check-expect (rechts-of-draaien-cat (make-Vcat -39 100 "right")) 
(make-Vcat -36 99.9 "right"))
(check-expect (rechts-of-draaien-cat (make-Vcat 1040 100 "right")) 
(make-Vcat 1040 99.9 "left"))
(define (rechts-of-draaien-cat s)
(if ( > (Vcat-Xcat Vcat) bovengrens-cat)
    (make-Vcat  (Vcat-Xcat s)  (- (Vcat-Hcat s) move-gauge) "left")
    (make-Vcat (+ (Vcat-Xcat s) move-animal) (- (Vcat-Hcat s) 
move-gauge) "right"))
)

; Vanimal -> Vanimal
; Function which change the world on clock ticks.
; On every tick the X-coordinate changes 3 pixels and the happiness 
decrease with 0.1.
   (define (tock s)
     (cond
       [(Vcat? s)(if(equal? (Vcat-Richting s) "left") 
(links-of-draaien-cat Vcat) (rechts-of-draaien-cat Vcat))]
       [(Vcham? s) (if(equal? (Vcham-Richting s) "left") 
(links-of-draaien-cham Vcham) (rechts-of-draaien-cat Vcham))]
))

(define (render s)s)

(define (main s)
   (cond
     [(Vcat? s) (big-bang s (check-with Vcat?) (on-tick tock) (on-draw 
render) )]
     [(Vcham? s) (big-bang s (check-with Vcham?) (on-tick tock) (on-draw 
render) )]
     ))

(main (make-Vcat 12 100 "left"))

Is this better ?

Roelof


Op 30-6-2012 9:03, Roelof Wobben schreef:
> Op 30-6-2012 1:38, Neil Van Dyke schreef:
>> Stephen Bloch wrote at 06/29/2012 06:01 PM:
>>> Either you introduce this stuff much better than I do, or your 
>>> students are much sharper.
>>
>> 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.
>>
>> 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.)
>>
>> Neil V.
>>
>> ____________________
>>  Racket Users list:
>> http://lists.racket-lang.org/users
>>
>
>
> Im rereading the chapter and I think I found a piece of the puzzle.
>
> In the chapter there is a mention of this :
>
> ;A SIGS(short for "space invader game state") is one of:
> ;--(make-aimUFO <#%28tech._mix._ufo%29>Tank <#%28tech._mix._tank%29>)
> ;--(make-firedUFO <#%28tech._mix._ufo%29>Tank 
> <#%28tech._mix._tank%29>Missile <#%28tech._mix._missile%29>)
>
>
>
> I can do the same for my problem.
>
> ; A Vanimal is one of :
> ; - (make-Vcat ( x happiness)
> ;   (make-Vcham ( x happiness)
>
> So Vanimal is not a struct but strictly a name.
>
> Am I on the right track.
>
> Roelof
>
>
>
>
> ____________________
>    Racket Users list:
>    http://lists.racket-lang.org/users


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120630/660e0c19/attachment-0001.html>

Posted on the users mailing list.