[plt-scheme] arrow.ss teachpack

From: Connor Ferguson (psfreak at linkline.com)
Date: Sat Feb 28 17:26:51 EST 2004

I get the loop thing, Bruce,  but I am still having trouble with the

When you said that move-picture needed to return the translated shape, I
figured that instead of changing move-picture, I could just use
translate-losh. Anyway, I changed the definitions for ud-lander and
lr-lander and added the extra item to process like you said.

;; ud-lander : list-of-shapes number  -> boolean
(define (ud-lander LUNAR delta)
  (translate-losh LUNAR 'ver delta))
;; lr-lander : list-of-shapes number -> boolean
(define (lr-lander LUNAR delta)
  (translate-losh LUNAR 'hor delta))
(start 300 300)
(draw-losh LUNAR)
(control-up-down LUNAR 10 ud-lander draw-losh)

When executing, this draws the lander and comes up with the up and down
arrows. However, when I click on one of the arrows, it highlights the cond
statement of translate losh and says that all question results were false.

;; translate-losh : list-of-shapes symbol number -> list-of-shapes
(define (translate-losh alosh dir delta)
    [ (empty? alosh) empty]
    [ (cons? alosh) (cons (translate-shape (first alosh) dir delta)
                         (translate-losh (rest alosh) dir delta))]))

Thank you so so much for helping me!! I really appreciate it.

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

> Connor Ferguson wrote:
>> For list-related administrative tasks:
>> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>> 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.
>> Thanks,
>> Connor
>>> (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)))))
> This loop is just a function like every function you have seen so far.
> I could have named it anything.  A good name for it is endless-loop
> because it DOESN'T END until you kill the program.
> The function loop is calling itself with a new lander to draw.
> Do you see how this is the same function?
> (define (does-not-end key losh)
> (cond
> ((eq? key 'left)  (does-not-end
> (get-key-event) (lr-lander -5 losh))
> ((eq? key 'right) (does-not-end
> (get-key-event) (lr-lander 5 losh)))
> (else (does-not-end (get-key-event) losh))))
> There are other better ways of doing this but that will have to wait
> until you learn a bit more.
> Good luck!
> Bruce

Posted on the users mailing list.