[plt-scheme] HtDP newbie question, 12.4.2

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Fri Mar 28 07:55:52 EDT 2008

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 <matthias 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.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20080328/841563f7/attachment.html>

Posted on the users mailing list.