[plt-scheme] HtDP newbie question, 12.4.2

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Thu Mar 27 08:49:55 EDT 2008

On Mar 25, 2008, at 1:48 PM, Cooke Kelsey wrote:
> I am trying to learn HtDP by myself, and like Dave Yrueta I am  
> stumped by 12.4.2.

[Oops I forgot to reply to his last message.]

> ; Purpose: to insert a symbol between every letter of every word,  
> e.g. X, AT-->XAT, AXT, ATX.

Please reformulate the example in terms of symbols and lists.

>  ;Function Template:
> (define (insert-everywhere/in-all-words s low)
>   (cond
>     [(empty? (rest low))...]
>     [else ...(first low)...insert-everywhere/in-all-words s (rest  
> low)]))
> Note:
> It is suggested to use "append", which is easy one or two times--- 
> (append x word) or (append (append (first word) x) (rest word))---- 
> but I can't see how to use this recursively for an arbitrary number  
> of letters and words.

So far so good. Let's try what HtDP/2e will introduce:

Please make a table of the following shape:

  s   |   low  |   (first low)  |  (insert-everywhere/in-all-words s  
(rest low) | expected result for (insert-... s low)
  X   |   AT   |     ?             |  use the purpose statement to  
determine this |   (list `XAT' `AXT' `ATX')

As I said, you need to reformulate this in terms of symbols and  
lists. If it doesn't jump out at you how to go from the four columns  
to the last one, then make a couple of more examples. I am pretty  
sure it will. Here is the rule of thumb:

  --> you know of a built-in function/primitive that does the work
  --> you don't. in this case, you make a wish: a purpose statement  
and a contract for a helper function that does it for you.

You may also have to combine a primitives with functions.

Please report back -- Matthias

> The fact that the "hint" refers to the keyword list, which the book  
> hasn't covered yet, makes me wonder if it's even possible to answer  
> this problem, given what we know so far...
> Thanks very much,
> Cooke
> 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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20080327/24acb1bb/attachment.html>

Posted on the users mailing list.