<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">
<br><div><html>On Mar 27, 2008, at 1:20 PM, Cooke Kelsey wrote:</html><br class="Apple-interchange-newline"><blockquote type="cite"><div>Dear Dr. Felleisen, </div>  <div>thanks so much for responding!  Your suggestions really helped me to think about the problem.</div>  <div> </div>  <div>Here's a table of examples, as you suggested:</div>  <div> </div>  <div>;;Examples <br>; s | low              |(first..)|(rest..)    | result</div></blockquote><div><br></div><div>Q: What do you mean with (rest ..) ?  This doesn't look like my table. </div><div><br></div><br><blockquote type="cite"><div>;--------------------------------------------------------------------------------------------------------<br>; X | '(AT)            |'(AT)    |empty       | '((XAT) (AXT) (ATX))</div></blockquote><div><br></div><div><br></div><div>[This isn't quite right! 'AT is NOT the representation of the English word "at".]</div><div><br></div><br><blockquote type="cite"><div>; X | '((AB) (CD) (EF))|'(AB)    |'((CD) (EF))| '((XAB) (AXB) (ABX) (XCD) (CXD) (CDX) (XEF) (EXF) (EFX))</div></blockquote><div><br></div>This second row looks hyper-complicated. </div><div><br></div><div>Q: Why not take one step from row 1, which uses a list with one word. What would be the next case? </div><div><br></div><div><div><br></div><div><br></div><br><blockquote type="cite"><div><span class="Apple-style-span" style="-webkit-text-stroke-width: -1; ">Here's an attempt to "go from the first columns to the last": </span></div>  <div><br>; Definitions:<br>(define (insert-everywhere/in-all-words s low)<br>  (cond<br>    [(empty? (rest low)) empty]<br>    [else (append (insert-in-single-word s (first low)) (insert-everywhere/in-all-words s (rest low)))]))</div></blockquote><div><br></div><div>Good the first leap went fine. </div><div><br></div><br><blockquote type="cite">  <div> <span class="Apple-style-span" style="-webkit-text-stroke-width: -1; ">(define (insert-in-single-word s word)</span></div><div>  (cond<br>    [(empty? (rest word)) empty]<br>    [else (append (list (first word) s (rest word)) (insert-in-single-word s (rest word)))]))</div></blockquote><div><br></div><div>The second leap went wrong. Why? </div><div><br></div><div>Is it possible that you JUMPED?  Why don't you turn the above examples into examples for this function. And *please* do provide a contract, a purpose statement. </div><div><br></div><div>-- Matthias</div><div><br></div><div><br></div><br><blockquote type="cite"><div><br></div>  <div>Unfortunately, the list of words gets shorter and shorter (sATX, sTX, sX).  I tried to think of a way to add a recursive "prefix" that gets longer, but each time the function cycles the first letters seem to disappear into the void...</div>  <div><br><b><i>Matthias Felleisen &lt;<a href="mailto:matthias@ccs.neu.edu">matthias@ccs.neu.edu</a>></i></b> wrote:</div>  <blockquote class="replbq" style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #1010ff 2px solid"><br>  <div>On Mar 25, 2008, at 1:48 PM, Cooke Kelsey wrote:  <blockquote type="cite">  <div><span class="Apple-style-span" style="-webkit-text-stroke-width: -1">I am trying to learn HtDP by myself, and like Dave Yrueta I am stumped by 12.4.2. </span></div></blockquote>  <div><br></div>[Oops I forgot to reply to his last message.]<br><br><br>  <blockquote type="cite">  <div><span class="Apple-style-span" style="-webkit-text-stroke-width: -1">; Purpose: to insert a symbol between every letter of every word, e.g. X, AT-->XAT, AXT, ATX.</span></div></blockquote>  <div><br></div>  <div>Please reformulate the example in terms of symbols and lists. </div>  <div><br></div><br>  <blockquote type="cite">  <div> <span class="Apple-style-span" style="-webkit-text-stroke-width: -1">;Function Template: </span></div>  <div>(define (insert-everywhere/in-all-words s low)<br>  (cond<br>    [(empty? (rest low))...]<br>    [else ...(first low)...insert-everywhere/in-all-words s (rest low)]))<br></div>  <div>Note: </div>  <div>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. </div></blockquote>  <div><br></div>  <div>So far so good. Let's try what HtDP/2e will introduce: </div>  <div><br></div>  <div>Please make a table of the following shape: </div>  <div><br></div>  <div> s   |   low  |   (first low)  |  (insert-everywhere/in-all-words s (rest low) | expected result for (insert-... s low)</div>  <div>--------------------------------------------------------------------------------------------------------</div>  <div> X   |   AT   |     ?             |  use the purpose statement to determine this |   (list `XAT' `AXT' `ATX')</div>  <div><br></div>  <div><br></div>  <div>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: </div>  <div><br></div>  <div> --> you know of a built-in function/primitive that does the work </div>  <div> --> 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. </div>  <div><br></div>  <div>You may also have to combine a primitives with functions. </div>  <div><br></div>  <div>Please report back -- Matthias</div>  <div><br></div>  <div><br></div>  <div><br></div>  <div><br></div>  <div><br></div>  <div><br></div><br>  <blockquote type="cite">  <div></div>  <div> </div>  <div>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...</div>  <div> </div>  <div>Thanks very much, </div>  <div> </div>  <div>Cooke</div>  <div><br class="khtml-block-placeholder"></div>  <hr size="1">  Looking for last minute shopping deals? <a href="http://us.rd.yahoo.com/evt=51734/*http://tools.search.yahoo.com/newsearch/category.php?category=shopping">Find them fast with Yahoo! Search.</a>  <div style="MARGIN: 0px">_________________________________________________</div>  <div style="MARGIN: 0px"><span class="Apple-converted-space">  </span>For list-related administrative tasks:</div>  <div style="MARGIN: 0px"><span class="Apple-converted-space">  </span><a href="http://list.cs.brown.edu/mailman/listinfo/plt-scheme">http://list.cs.brown.edu/mailman/listinfo/plt-scheme</a></div></blockquote></div><br></blockquote><br><div>       <br class="khtml-block-placeholder"></div><hr size="1">Looking for last minute shopping deals? <a href="http://us.rd.yahoo.com/evt=51734/*http://tools.search.yahoo.com/newsearch/category.php?category=shopping"> Find them fast with Yahoo! Search.</a></blockquote></div><br></body></html>