[plt-scheme] Re: HtDP newbie question, 12.4.2

From: dave yrueta (dyrueta at gmail.com)
Date: Fri Mar 28 09:48:24 EDT 2008

Cooke --

Don't despair.  Hang in there.  You're so close!

When I was working on this thing, I was concerned there was only 1
solution, and finding it was going to be a matter of luck.  Don't
worry, there is more than one solution, and they are entailed in

Up to this point in HtDP, list processing functions dealing with
symbols generally either searched for symbols among a list, or built
lists which were some variation of the original list.  In all cases, I
believe, the function would examine the first element of the list,
either save or discard it, and then recur.  So it seems natural that
any list-processing function could only produce a list of symbols with
a length either equal to or less than the original list.

So you're asking yourself, given a word, or a list-of-symbols with,
for example, four-letters, how in the heck do I produce a list-of-
words 5 words long, with each word the length of original word? Am I,
as they say, feeling you?

(List-of-words 5 words long = 1 (insert-symbol at beginning of word) +
3 (insert symbol into middle positions) + 1 (insert symbol at end of

I can sympathize, for a newbie this is a truly maddening question, and
solving it is like giving birth.....

My advice is to pay extremely close attention to Matthias' last hint
-- it is very telling:

* If a list X misses the symbol 'A (at the front), how do you get a
list that has the 'A and all of X?

* X = (list 'X 'T) and 'A --> I want (list 'A 'X 'T). How do I do

Answer those questions in the simplest and most natural terms you can
come up with, sit it on it for awhile, and the answer may come to

I know this is probably not very helpful, but as someone who also
struggled mightily with this problem, I just wanted to offer you some
words of encouragement.  I'm extremely curious to see what you come up

Good luck!

Dave Yrueta

On Mar 28, 4:55 am, Matthias Felleisen <matth... at ccs.neu.edu> wrote:
> Here is a definition of 'adding in the missing element':
> * If a list X misses the symbol 'A (at the front), how do you get a
> list that has the 'A and all of X?
> * X = (list 'X 'T) and 'A --> I want (list 'A 'X 'T). How do I do that?
> -- Matthias
> On Mar 28, 2008, at 2:54 AM, Cooke Kelsey wrote:
> > You wrote:
> > "Where should this missing letter get added in the result of
> > (insert-in-single-word s (rest word))? Correct! At the beginning."
> > It's not possible to add missing letters...they are missing!
> > What I need is a prefix function.  For the word (list 'A 'T 'W), I
> > need:
> > cycle 1: (empty)
> > cycle 2: (list 'A)
> > cycle 3: (list 'A 'T)
> > cycle 4: (list 'A 'T 'W)
> > Unfortunately, the recursive function call, "insert-in-single-word
> > (rest word)," results in smaller and smaller words:
> > cycle 1: 'T 'W
> > cycle 2: 'W
> > cycle 3: empty
> > I just spent 2 hours trying to define an auxiliary function or add
> > some extra "appends" in the main function, in order to insert a
> > prefix in front of the X, but there is no way to add the missing
> > letters.  They are gone forever.
> > Matthias Felleisen <matth... at ccs.neu.edu> wrote:
> > On Mar 27, 2008, at 10:04 PM, Cooke Kelsey wrote:
> >> Hi, I think I see what you are driving at.
> > ...
> >> the words are missing the letter A, the first of the current
> >> (****) word
> > ...
> >>  I thought of your reminder to use helper functions, e.g. "add-
> >> prefix," but I keep going back to this register idea.  I don't
> >> know whether I am getting off track or what.
> > What would "add-prefix" do? "Register" sounds like an old man's way
> > of thinking about machines and lower-level representations of
> > computations yet. But add-prefix seems definitely related to the
> > "it's missing the letter ..." part.
> > Where should this missing letter get added in the result of (insert-
> > in-single-word s (rest word))? Correct! At the beginning.
> > Keep going. -- Matthias
> > Looking for last minute shopping deals? Find them fast with Yahoo!
> > Search.
> _________________________________________________
>   For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme

Posted on the users mailing list.