[plt-scheme] move-circle problem

From: arnuld fraser (arnuld3 at gmail.com)
Date: Thu Jan 12 07:18:22 EST 2006

Hello everyone,

 i will be as brief as i can in explainig the problem. this is the original
code of exercise-6.6.6 copied as it is from online version & also from the
printed book:

  (move-circle 10
    (move-circle 10
      (move-circle 10
        (move-circle 10 ... a circle ...)))))

;; the last line says ... a circle....  without giving any hint what "a
circle" is . i think it is a printing mistake and it should be
"...a-circle...". even after changing it to "a-circle"  the function does
not work.

 (draw-a-circle (move-circle 10 (move-circle 10 (move-circle 10 (move-circle
10 a-circle)))))

and i got following ouput:

Welcome to DrScheme, version 209.
Language: Beginning Student.
Teachpack: /usr/lib/plt/teachpack/htdp/draw.ss.
color-circle-center: expects argument of type <struct:color-circle>; given

"true" is from the innermost expression  as it moves the cicle 1st time but
next lies error.

it does not move the circle 4 times as told in the book. I think i know the
reason. from my common sense  (move-circle 10 a-circle) produces not the
circle but "true" & hence "true" goes intop drscheme not the circle itself .
I have  verified this thing from "stepper" too. since (move-circle..) did
not get its 2nd parameter as structue it reports an error for it got "true"
- the boolean.

i am using DrScheme version 209 on Debian "sarge".i got 209 version with the
debian's 14 CD packs, but i also tried "plt-209-bin-i386-linux.sh" onto
Fedora Core but again the same problem.

I have studied only upto chapter 6 of HTDP and i do not know any other
language, so please
keep the answer according to the HTDP's way.

 may you help me?

thanks in advance

------------------- here is the programme

(define-struct color-circle (center radius color))
;; A color-cirlce is a structure: (make-color-circle cen r col)
;; where cen is a posn structure, r is a number and col is a symbol.

;; in-circle? : a-color-circle, a-posn -> boolean
;; to deiermine whether the point lies inside the circle or not.

#| Template:
(define (fun-for-circle a-circle a-posn)
  ...(color-circle-center a-circle)...
  ...(color-circle-radius a-circle)...
  ...(color-circle-color a-circle)...) |#

(define (move-circle delta a-circle)
    [(draw-and-clear-circle a-circle) (translate-circle a-circle delta)]
    [else a-circle]))

(define (translate-circle a-color-circle delta)
  (draw-circle (make-posn (+ delta (posn-x (color-circle-center
                          (posn-y (color-circle-center a-color-circle)))
               (color-circle-radius a-color-circle)
               (color-circle-color a-color-circle)))

(define (draw-and-clear-circle a-circle)
  (and (draw-a-circle a-circle)
       (sleep-for-a-while 1)
       (clear-a-circle a-circle)))

(define (draw-a-circle a-circle)
  (draw-circle (color-circle-center a-circle)
               (color-circle-radius a-circle)
               (color-circle-color a-circle)))

(define (clear-a-circle a-circle)
  (clear-circle (color-circle-center a-circle)
                (color-circle-radius a-circle)
                (color-circle-color a-circle)))

;; test
(define a-circle (make-color-circle (make-posn 30 30) 10 'red))

(start 300 300)
(draw-a-circle (move-circle 10 (move-circle 10 (move-circle 10 a-circle))))

--------------------- end of programme -------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20060112/9e82355a/attachment.html>

Posted on the users mailing list.