[plt-scheme] HTDP Exercise 12.3.1

From: S Brown (ontheheap at gmail.com)
Date: Fri Apr 24 19:35:06 EDT 2009

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)


Posted on the users mailing list.