[plt-scheme] Re: HTDP Exercise 12.4.2 ... Help!
An alternative view is to insert the LETTER x into every position of
ONE WORD. -- Matthias
On Apr 26, 2009, at 5:37 PM, S Brown wrote:
> I've been working on this for the last few hours, and my insert-
> everywhere function is now working like so:
>
> (insert-everywhere 'x (list 'h 'o 't))
>
> => (list (list 'x 'h 'o 't)
> (list 'x 'o 't)
> (list 'x 't)
> (list 'x))
>
> So, I wish I had some function that would prefix each list with the
> "remainder" of the word, such that:
>
> (list (prefix remainder (list 'x 'h 'o 't))
> (prefix remainder (list 'x 'o 't))
> (prefix remainder (list 'x 't))
> (prefix remainder (list 'x)))
>
> => (list (list 'x 'h 'o 't)
> (list 'h 'x 'o 't)
> (list 'h 'o 'x 't)
> (list 'h 'o 't 'x))
>
> So, based on this I want a function, prefix, which basically takes two
> words, appends them, and returns the new list. So, I guess in order to
> use this "prefix" function, I need to figure out how to define
> "remainder," but now I seem to be stuck again because remainder
> depends on information that isn't being passed along (ie, for (prefix
> remainder (list 'x 't)), remainder needs to be (list 'h 'o), but I
> can't figure out how to do this!
>
> Am I at least on the right path with this? Any tips/hints??
>
> On Apr 26, 1:25 pm, Matthias Felleisen <matth... at ccs.neu.edu> wrote:
>> Yes, and don't forget, you may need *more* auxiliary functions than
>> just insert-everywhere
>>
>> On Apr 26, 2009, at 1:19 PM, S Brown wrote:
>>
>>
>>
>>> Thanks for the input so far. I don't know how I didn't see this
>>> before! Instead of calling append on (list s) (first a-low), what I
>>> need is to call append on another function which takes as it's
>>> arguments a symbol and a single word, which returns a list of words
>>> where the symbol has been been inserted before and after each letter
>>> in the word. In other words, where insert-everywhere/in-all-words is
>>> concerned with a list of words, my new function is only concerned
>>> with
>>> a single word.
>>
>>> So, now it's a matter of going through the design process for my new
>>> function, which I'm going to call insert-everywhere.
>>
>>> ;; insert-everywhere: symbol word -> list-of-words
>>> ;; to create a list-of-words where symbol s is inserted before
>>> ;; and after each letter in the word w
>>> (define (insert-everywhere s w)
>>> (cond
>>> ((empty? w) ... s ...)
>>> (else ... s (first w) ...
>>> ... (insert-everywhere s (rest w)) ...)))
>>
>>> I think this makes sense. Now it's a matter of completing each cond
>>> line in my new function insert-everywhere.. and figuring out how to
>>> actually insert a letter into each position of a word.
>>> _________________________________________________
>>> For list-related administrative tasks:
>>> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>>
>> _________________________________________________
>> For list-related administrative tasks:
>> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme