<div>Here's the answers to your questions:</div> <div> </div> <div>Q: What do you mean with (rest ..) ? This doesn't look like my table. </div> <div> </div> <div> A: Your table says, "(insert-everywhere/in-all-words s (rest low)," which means I would rewrite the whole function in the column? I guess I don't understand the purpose of the fourth column. The table is very helpful though.</div> <div> </div> <div>[This isn't quite right! 'AT is NOT the representation of the English word "at".]</div> <div> </div> <div> A: I was trying to use shorthand from Intermezzo 2:</div><PRE class=schemeresponse><SPAN class=keyword>'</SPAN>(<SPAN class=variable>a</SPAN> <SPAN class=variable>b</SPAN> <SPAN class=variable>c</SPAN>) <SPAN class=comment>This short-hand is an abbreviation for</SPAN> (<SPAN class=builtin>list</SPAN> <SPAN class=keyword>'</SPAN><SPAN class=variable>a</SPAN> <SPAN class=keyword>'</SPAN><SPAN
class=variable>b</SPAN> <SPAN class=keyword>'</SPAN><SPAN class=variable>c</SPAN>) </PRE> <div> </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> </div> <div>A: Um, two words. I have no idea why I did that.</div> <div> </div> <DIV>Q: The second leap went wrong. Why? 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> </DIV> <DIV>A: OK, this is where my big problem is. I'm not sure what you mean by JUMPED. Can you be more specific? I realize this is some kind of clue but I am too slow to get it. </DIV> <DIV> </DIV> <DIV>Here's a full design recipe:</DIV> <DIV> </DIV> <div>; Purpose: to insert a symbol between every letter of a single word<BR>; Contract: symbol word --> list of
words<BR>; Example: (define (insert-in-single-word X AT). Result should be (XAT AXT ATX)<BR>; Template: <BR>; (define (insert-in-single-word s word)<BR>; (cond<BR>; [(empty? (rest word)) empty]<BR>; [else (append (list (first word) s (rest word)) (insert-in-single-word s (rest word)))]))<BR></div> <div>Thanks very much.<BR><BR><B><I>Matthias Felleisen <matthias@ccs.neu.edu></I></B> wrote:</div> <BLOCKQUOTE class=replbq style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #1010ff 2px solid"><BR> <DIV>On Mar 27, 2008, at 1:20 PM, Cooke Kelsey wrote:<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 <<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></BLOCKQUOTE><BR><p> 
<hr size=1>Never miss a thing. <a href="http://us.rd.yahoo.com/evt=51438/*http://www.yahoo.com/r/hs"> Make Yahoo your homepage.</a>