[plt-scheme] arrow.ss teachpack

From: Connor Ferguson (psfreak at linkline.com)
Date: Sat Feb 28 16:34:56 EST 2004

Thanks a lot. Is there a place (in HTDP) that I can go to learn about that
loop thing? I'd like to know exactly what I'm putting into my code and how
it works instead of just doing it. Also, if I say to my teacher "someone on
the Scheme discussion forum told me to do this" I'm not really learning
anything. Don't get me wrong, you're advice is life-saving, I just want to
understand and learn more.


on 2/28/04 1:04 PM, Bruce Hauman at bhauman at cs.wcu.edu wrote:

> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> Connor Ferguson wrote:
>> (define (move-picture alosh dir delta)
>> (cond
>> [ (empty? alosh) empty]
>> [ (cons? alosh) (and (draw-and-clear-picture alosh)
>> (draw-losh (translate-losh alosh dir delta)))]))
> Connor, this function needs to return the translated shape for the
> control-up-down function to work.
>> (define (ud-lander delta)
>> (move-picture LUNAR 'ver delta))
>> ;; lr-lander : number -> boolean
>> (define (lr-lander delta)
>> (move-picture LUNAR 'hor delta))
> These two functions have to take one more argument; the shape itself as so:
> (define (ud-lander delta LUNAR)
> (move-picture LUNAR 'ver delta))
> This is also neccesary for control-up-down to work properly.
> If you want to use get-key-event you will need to use some sort of loop
> like this:
> (define (loop LUNAR)
> (let ((key (get-key-event)))
> (cond
> ((eq? key 'left)  (loop (lr-lander -5 LUNAR)))
> ((eq? key 'right) (loop (lr-lander 5 LUNAR)))
> (else (loop LUNAR)))))
> Again this relies upon lr-lander to return the new shape which ahs been
> translated to a new position.
> Also if you could figure out a way to erase the old shape and then draw
> a new translated one you wouldn't have to use sleep-for-a-while.
> Something like
> (cond
> [(and (clear-losh ...)
> (draw-losh  ...))
> (translate-losh ....)]
> ...)
> Try to redefine move-picture to look like that.
> Keep up the good work!
> Bruce

Posted on the users mailing list.