[plt-scheme] HtDP 12.4.2 question details

From: David Yrueta (dyrueta at gmail.com)
Date: Sat Apr 4 14:44:11 EDT 2009

Hi Grant --
A few suggestions:

First, if you use the list function, make sure your data definitions for
word and list-of-word use them too.  More than any other problem I've
encountered so far in HtDP, the interactions between contracts and data
definition are what drive the design decisions that ultimately lead to the
successful solution of this exercise.

Second, when formulating the data definition for list-of-words, consider the
data-definition for 'polygons' in section 12.3.

Third, if you are thinking about introducing a third variable into one of
the auxiliary functions, as this suggests  (insert-everywhere-h char word
0)), don't.  I made a similar mistake and it cost me dearly!  Always refer
to the template for structural recursion when designing auxiliary functions,
which I think can be summed up as (first a-list).... (recursive-function
(rest a-list)).  Stick to that structure, and allow the data definitions and
contracts to guide the function design.

Hope that helps!  Good luck!

Dave Yrueta

On Sat, Apr 4, 2009 at 10:04 AM, Marco Morazan <morazanm at gmail.com> wrote:

> >
> > The thing is that I ignored what I saw and defined (insert-everywhere
> > char word) first:
> >
> > (define (insert-everywhere char word)
> >  (insert-everywhere-h char word 0))
> >
> > ; insert-everywhere-h : symbol word integer -> list-of-words
> > ; to generate a list-of-words by inserting char into
> > ; word in every possible position
> >
> > This function is like the insert functions in this chapter, and stops
> > when it reaches the length of the word (which is the last position).
>
> Hmmm....what is the role of that integer? Do you really need it? If
> the integer is redundant get rid of it and eliminate that helper
> function (i.e. the *-h function).
>
> My suggestions:
>
> 1. Start with the template for functions on words.
> 2. Ask yourself:
>    a. What do you expect from (insert-everywhere-h char (rest word))?
>    b. What is missing from your answer to a.
>    c. How do you build the needed answer from (first word) and the answer
> to a.
>
> Keep in mind that if you need to build a result of arbitrary length
> for c, then you probably want to design an auxilary function to do
> that.
>
> --
>
> Cheers,
>
> Marco
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20090404/e153ab3d/attachment.html>

Posted on the users mailing list.