[plt-scheme] Novice needs help writing function

From: dave yrueta (dyrueta at gmail.com)
Date: Thu Dec 27 12:55:31 EST 2007

Hi All --

I'm a novice programmer embarking on a self-study course with "How to
Design Programs" and I'm stuck on a problem that's driving me nuts!
Some help would be greatly appreciated.

The problems asks you to write a function which recursively mimics the
following sequence of function calls --

       (move-picture 1
             (move-picture 1
                  (move-picture 1
                        move-picture 1 FACE)

-- where "draw-list-of-shapes" is a function which consumes a single
"shape" structure, draws the shape by referring to other drawing
functions, and returns "true;"

--"move-pictures" consumes a number and a "shape" structure, draws and
clears the shape and then returns a shape structure incremented by the
value of the "number" parameter on the x axis of the drawing canvas,

--"FACE" is a list of shapes resembling a human face.

The challenge for me in writing this function is dealing with the list
output of the "move-picture" function, which, since it's not boolean,
cannot be evaluated within a conditional expression.  So the closest
I've gotten to a solution is this function --

(define(apply-n n)
    [(zero? n) true]
    [else (and(apply-n (sub1 n))(draw-losh(move-picture (+ 1 n)

The problem with this solution is that it draws 5 faces incremented by
a value of 1 pixel across the x axis, instead of drawing a shape,
clearing it, and then drawing the new "translated" shape, as the
problem requests.

Any thoughts?  Here's the full text of the problem in case I've
explained it poorly:

Exercise 11.2.3.   Develop apply-n. The function consumes a natural
number, n. It applies the function move from exercise 10.3.6 n times
to FACE, the list of shapes from exercise 10.3.1. Each application
should translate the shape by one pixel. The purpose of the function
is to simulate a continuously moving shape on a canvas, the last
missing piece of the extended exercise 10.3.

Thanks for your help!  This is my first time posting, so your support
is greatly appreciated!


Posted on the users mailing list.