[plt-scheme] HtDP 12.4.2 question details

From: Marco Morazan (morazanm at gmail.com)
Date: Sat Apr 4 13:04:38 EDT 2009

> 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




Posted on the users mailing list.