[plt-scheme] Help: Drawing polygons within world

From: Danny Yoo (dyoo at hkn.eecs.berkeley.edu)
Date: Sat Dec 2 16:32:40 EST 2006

> I'm trying to write a program that draws a polygon from a list of posns by
> using world.ss.  Here is my code so far:

Hi Sertac,

When we look at the CONNECT-DOTS function:

> (define connect-dots
> (lambda (w)
>  (cond
>    [(null? (cdr (world-lop w))) w]
>    [else
>     (and (place-image (add-line scene (posn-x (car (world-lop w))) (posn-y
> (car (world-lop w))) (posn-x (second (world-lop w))) (posn-y (second
> (world-lop w)))'black) 0 0 scene) (make-world (world-scene w) (cdr
> (world-lop w))))])))

then I agree: it does look incomplete.

Take advantage of structural induction and the design recipe.  You should 
be able to see what's wrong if you go through the design recipe steps more 

     * What is 'w'?  What's is the contract for CONNECT-DOTS?  This is
       important because, at the moment, I can't tell the intended return
       type either.

     * What's the purpose statement?  Document it.

     * What is the function template for a function that consumes the type
       of w?

Once you've done the recipe, go back to your function implementation and 
review what you have against it (especially with the function template). 
You should notice something peculiar.

Also, make up your mind when you use FIRST and REST vs CAR and CDR. 
Mixing CAR, CDR, FIRST, SECOND all up like this is just making it 
intentionally difficult for us.  *grin*

Good luck to you!

Posted on the users mailing list.