[plt-scheme] HTDP Exercise 12.3.1

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Sat Apr 25 11:03:38 EDT 2009

Let's start with the problem statement:

> Modify draw-polygon so that it adds the first item of a-poly to its  
> end. This requires a different auxiliary function: add-at-end.

This suggests the following

  draw-at-end uses as body (connect-dots (add-at-end (first a-poly) a- 


;; add-at-end : Number Polygon -> Polygon
;; add x to the end of p
(define (add-at-end x p)

If you solved this auxiliary problem with an example/test like the  
one you proposed below, you're done. Think through this and figure  
out why.

If you didn't solve this problem, shows us how far you got with the  
design recipe.

>> I have also posted this to the Study-HTDP group, but that group
>> doesn't seem to be very active)

I had no clue this existed :-)

On Apr 24, 2009, at 7:35 PM, S Brown wrote:

> I'm not sure how to do this exercise correctly.
> My thoughts are as follows:
> add-at-end needs to take a list, and return a new list, with the first
> element of the list appended to the end of the new list. (IE - list
> going in is 10 5 1, list coming out should be 10 5 1 10). My initial
> solution was to require add-at-end to receive two arguments, an item
> and a list, and have the specified item added to the end of the
> specified list. So, in practice it ended up being used like this:
> (add-at-end (first a-poly) a-poly)
> This works, but I think I'm missing something here. I have tried going
> through the design process, but I'm getting stuck because I haven't
> been able to figure out another way of "retaining" that first value so
> that it can be appended to the end. The only other solution I have
> been able to come up with is something such as:
> (define (add-at-end a-poly)
>    (add-at-end2 (first a-poly) a-poly))
> where add-at-end2 is the same definition as the original add-at-end.
> So, is there a better, or rather a more correct way of solving this
> exercise, or is this solution acceptable?
> Thanks.
> (I have also posted this to the Study-HTDP group, but that group
> doesn't seem to be very active)
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme

Posted on the users mailing list.