[racket] exercise 6.6.3 htdp

From: frank weytjens (fweytjens.android at gmail.com)
Date: Wed Nov 30 07:11:10 EST 2011

(define H 300)
(define L 300)
(define-struct cirkel (posn number color))
(define cirkel1 (make-cirkel(make-posn (/ H 2) (/ L 2)) (/ L 4) 'red))
;; fun-for-circle: circle --> ?
;;(define (fun-for-circle circle) ...)
;;(define (fun-for-circle c)
;;(draw-solid-disk (cirkel-posn c)(cirkel-number c) (cirkel-color c)))
(define (square x)(* x x))
(define (distance x1 x2) (- x1 x2))
(define (x-cirkel cirkel) (posn-x (cirkel-posn cirkel)))
(define (y-cirkel cirkel) (posn-y (cirkel-posn cirkel)))
(define (y-pos pos) (posn-y pos))
(define (x-pos pos) (posn-x pos))
(define (distance-to-center C pos)
 (sqrt (+(square(distance (x-cirkel C) (x-pos pos)))(square (distance
(y-cirkel C)(y-pos pos))))))

(define (in-circle? C pos)
  (> (cirkel-number C) (distance-to-center C pos)))

 (in-circle? cirkel1 (make-posn 150 224))  --> true
 (in-circle? cirkel1 (make-posn 150 225))  --> false

I'm not happy with my in-circle? function
to many define's  needed
nested structures is the main cause why this simple program becomes
but how can one solve this problem more elegant?


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20111130/10d8cdb8/attachment.html>

Posted on the users mailing list.