Hello,

I have this function :

; Vzoo -> Vzoo
; function which alters the happiness and x-coordinate based on the ticks of the computer. (check-expect (tock (make-VZoo (make-VCat 500 5 "rechts") (make-VCham 450 5 "rechts"))) (make-VZoo (make-VCat 503 4.9 "rechts")(make-VCham 453 4.9 "rechts"))) (check-expect (tock (make-VZoo (make-VCat 500 5 "rechts") (make-VCham 1032 5 "rechts"))) (make-VZoo (make-VCat 503 4.9 "rechts")(make-VCham 1032 4.9 "links"))) (check-expect (tock (make-VZoo (make-VCat 500 5 "rechts") (make-VCham 1032 5 "links"))) (make-VZoo (make-VCat 503 4.9 "rechts") (make-VCham 1029 4.9 "links"))) (check-expect (tock (make-VZoo (make-VCat 500 5 "rechts") (make-VCham 500 5 "links"))) (make-VZoo (make-VCat 503 4.9 "rechts")(make-VCham 497 4.9 "links")))
(define (tock s)
  (cond
[ (and ( < ( VCham-X (VZoo-VCham s)) bovengrens-cham ) (< (VCat-X (VZoo-VCat s)) bovengrens-cat) (string=? (VCham-R (VZoo-VCham s)) "rechts") (string=? (VCat-R (VZoo-VCat s)) "rechts")) (make-VZoo (make-VCat (+ (VCat-X (VZoo-VCat s)) 3) (- (VCat-H (VZoo-VCat s)) 0.1) "rechts")(make-VCham (+(VCham-X (VZoo-VCham s))3) (-(VCham-H (VZoo-VCham s)) 0.1) "rechts"))] [ (and ( > ( VCham-X (VZoo-VCham s)) bovengrens-cham ) (< (VCat-X (VZoo-VCat s)) bovengrens-cat) (string=? (VCham-R (VZoo-VCham s)) "rechts") (string=? (VCat-R (VZoo-VCat s)) "rechts")) (make-VZoo (make-VCat (+ (VCat-X (VZoo-VCat s) 3) (- (VCat-H (VZoo-VCat s)) 0.1) "rechts")(make-VCham (VCham-X (VZoo-VCham s)) (-(VCham-H (VZoo-VCham s)) 0.1) "links"))] [ (and ( > ( VCham-X (VZoo-VCham s)) ondergrens-cham ) (< (VCat-X (VZoo-VCat s)) bovengrens-cat) (string=? (VCham-R (VZoo-VCham s)) "links") (string=? (VCat-R (VZoo-VCat s)) "rechts")) (make-VZoo (make-VCat (+ (VCat-X (VZoo-VCat s)) 3) (- (VCat-H (VZoo-VCat s)) 0.1) "rechts" )(make-VCham (-(VCham-X (VZoo-VCham s))3) (-(VCham-H (VZoo-VCham s)) 0.1) "links"))]
  ))


I see that + and later on -3 are always there and that happiness is always - 0,1

Now I can make auxilery functions :

add-happiness ( number) increase-x (number) decrease-x (number) etc. but then things are not more readable as now I believe.
But I wonder if I can make better auxilery functions.
I do know have the knowlegde to make itemization functions so that not a right answer for me.

I work in DrRacket with the beginning student language.

Roelof

____________________
 Racket Users list:
 http://lists.racket-lang.org/users

Reply via email to