<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">
<div><br></div><div>Why did you throw away your progress (add-first-letter)? </div><div><br></div><div>Why did you not answer my second question? </div><div><br></div><div>(I'll give you that much: with the two you are about 10 keystrokes from the answer.) </div><div><br></div><div>I am getting the feeling your jumping again. </div><div><br></div><div>;; --- </div><div><br></div><div>Let's step back a bit. The purpose of this extended exercise is to practice the two ideas that the book has introduced at that point: </div><div><br></div><div>1. that the design recipe works on a per function basis -- BUT YOU NEED TO STICK TO IT; </div><div>2. that the 'wish list' works -- BUT YOU NEED TO STICK TO IT.  (If you are systematic about this, you just never forget where in the problem you are.) </div><div><br></div><div>;; --- </div><div><br></div><div>Another step back: </div><div><br></div><div>1. In case you're wondering:  most people would consider this exercise way beyond a first-semester exercise. (It was on my MS exam in 1981.) </div><div><br></div><div>2. HtDP/2e will use a simpler exercise than that and push back Arrangements until students have more practice. A lot of people have problems with it though in 1-1 meetings, it's much easier to tease out the answers to these questions because the speed is higher and less frustrating. </div><div><br></div><div><br></div><div><br></div><div>-- Matthias</div><div><br></div><div><br></div><div><br></div><div><br></div><br><div><html>On Mar 28, 2008, at 5:35 PM, Cooke Kelsey wrote:</html><br class="Apple-interchange-newline"><blockquote type="cite"><div>Dear Matthias / Marco,</div>  <div> </div>  <div>I read Marco's suggestions.  It was very helpful to read through the whole problem again in clear English and remember how I got to the function "insert-in-single-word."  I think I am near to the answer.</div>  <div> </div>  <div>You both ask me a similar question:<br></div>  <div>(1) Matthias:  Can you design a function that adds a letter (no matter what it is) to the front of all these words you have gotten back?...DONE? After that: what is missing? </div>  <div> </div>  <div>   given:          the recursion                           in the final result I want                     </div>  <div>  'X   "ATE"     "X" "TE" --> "XTE" "TXE" "TEX"     "AXTE" "ATXE" "ATXE" "ATEX"           <br></div>  <div>(2) Marco: "Here is where I believe you are really stuck. It is easy to see one member of the result: (letter a-word). This puts letter before the first letter of a-word. Is that the only place it can go? No, it can go before any of the letters in a word and at the end of a-word. How do you insert a letter everywhere in (rest a-word)? Once you have this list (call it R) all you need is to do something with (first a-word).  Where does it have to go in each of R?"<br></div>  <div> </div>  <div>OK, here is a function which I think answers these questions:</div>  <div> </div>  <div>(define (add-letter-to-recursive-list letter a-word)<br>  (cond<br>    [(empty? (rest a-word)) (cons (list letter (first a-word)) empty)]<br>    [else (cons (cons letter a-word) (add-letter-to-recursive-list letter (rest a-word)))]))</div>  <div> </div>  <div>;example:</div>  <div>(add-letter-to-recursive-list 'x (list 'w 'a 't 'e 'r))</div>  <div>;answer</div>  <div>(list<br> (list 'x 'w 'a 't 'e 'r)<br> (list 'x 'a 't 'e 'r)<br> (list 'x 't 'e 'r)<br> (list 'x 'e 'r)<br> (list 'x 'r))</div>  <div><br>Then next question is, how can I put the missing letters back on the front of these words?  </div>  <div> </div>  <div>For this, I can use the "add-first-letter" function which I sent earlier to Matthias:</div>  <div> </div>  <div>(define (add-first-letter first-letter low)<br>  (cond <br>    [(empty? (rest low)) (cons (append (list first-letter) (first low)) empty)]<br>    [else (cons (append (list first-letter) (first low)) (add-first-letter first-letter (rest low)))]))</div>  <div> </div>  <div>Now, I can combine the two functions into a main function, "add-letter-plus-prefix":</div>  <div> </div>  <div>(define (add-letter-plus-prefix x a-word)<br>  (add-first-letter (first a-word) (Rest x a-word)))</div>  <div> </div>  <div>;example:</div>  <div>(add-letter-plus-prefix 'x (list 'w 'a 't 'e 'r))</div>  <div>;answer:</div>  <div>(list<br> (list 'w 'x 'w 'a 't 'e 'r)<br> (list 'w 'x 'a 't 'e 'r)<br> (list 'w 'x 't 'e 'r)<br> (list 'w 'x 'e 'r)<br> (list 'w 'x 'r))</div>  <div> </div>  <div>It looks nice, but the word is still shrinking away.  I have simply added the first letter to the beginning of all the words.  My problem is still, how can I increment the prefix in order: 'w, 'a, 't, 'e, 'r?  </div>  <div> </div>  <div>At this point, I think my problem is too many levels of abstraction.  I think that you all can see the answer very clearly, but I can't visualize multiple recursive functions.  The tables, etc have been extremely helpful for me to develop the individual functions.  As far as the final solution, perhaps I don't have the ability to "see" it on that level of abstraction?</div>  <div> </div>  <div><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 28, 2008, at 1:24 PM, Cooke Kelsey wrote:<br class="Apple-interchange-newline">  <blockquote type="cite">  <div>Oh right, in order to include all the words I need more than an append.  Here's a function that adds a letter to ALL the words:</div>  <div><br>(define (add-first-letter first-letter low)<br>  (cond <br>    [(empty? (rest low)) (list (cons first-letter low))]<br>    [else (cons (cons first-letter (list (first low))) (add-first-letter first-letter (rest low)))]))<br></div>  <div>;example:</div>(add-first-letter 'X (list 'A 'T 'E 'Y 'W 'Z))   <div>;result:</div>  <div>(list (list 'X 'A) (list 'X 'T) (list 'X 'E) (list 'X 'Y) (list 'X 'W) (list 'X 'Z))</div></blockquote>  <div><br></div>  <div><br></div>  <div>So if you apply add-first-letter to (first word) and the result of (insert-everywhere/in-one-word (rest word)), you get back all but one of the word you want.  Which brings me to the second question: </div>  <div><br></div><br>  <blockquote type="cite">  <div> <span class="Apple-style-span" style="-webkit-text-stroke-width: -1">That was a lot more complicated than I thought.  I guess that should be a helper function. </span></div>  <div> </div>  <div>However, when I try to make a main function (insert-in-single-word) that calls add-first-letter, I end up going around in the same circle as before.</div></blockquote>  <div><br></div>  <div><br></div>  <div>Because you failed to read and answer my second question. -- Matthias</div>  <div><br></div>  <div><br></div>  <div><br></div>  <div><br></div><br>  <blockquote type="cite">  <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 28, 2008, at 12:34 PM, Cooke Kelsey wrote:<br class="Apple-interchange-newline">  <blockquote type="cite">  <div>OK, here's a simple function that adds a letter to a word:</div>  <div> </div>  <div>(define (add-first-letter first-letter word)<br>  (append (list first-letter) word))</div></blockquote>  <div><br></div>  <div><br></div>  <div>That's not what I asked you to _design_.  Please read the suggestion carefully. And again, (append (list foo) bar) is equal to (cons foo bar). Why do yu keep using append? </div>  <div><br></div>  <div><br></div><br>  <blockquote type="cite">  <div>(add-first-letter 'A (list 'X 'T 'E))=(list 'A 'X 'T 'E')<br></div>  <div>So my question is, where does (list 'A 'T 'E) come from? </div></blockquote>  <div><br></div>  <div>It is your sample input to the function. It says "Given" in that column. </div>  <div><br></div><br>  <blockquote type="cite">  <div>In your table below, you say "the recursion: "X" "TE" --> "XTE" "TXE" "TEX".  Actually I have never been able to create such a recursion.  That's the big mystery to me. </div></blockquote>  <div><br></div>  <div><br></div>  <div>The purpose statement of the function tells you what the recursive call should produce. So when you code, you may assume that the recursive call works properly.</div>  <div><br></div>  <div><br></div>  <blockquote type="cite">  <div></div>  <div><br></div>  <div>I just read Dave Yrueta's encouraging note, and he says I need to focus on your hint about adding 'A to the list, "in the simplest and most natural way."  Well, all I can think of is to append it, like I did above.  But there is no recursive element, and I cannot call it or plug it into the main recursive function.  It is floating out in space.</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">  <div><br></div>  <div>Okay you have gotten to the point where you're jumping even faster. Slogan: </div>  <div><br></div>  <div> furiously fast programming leads to nowhere. </div>  <div><br></div>  <div>;; --- </div>  <div><br></div>  <div>All I was getting at is a simple point: </div>  <div><br></div>  <div>Your recursive calls in insert-everywhere/one-word produced almost all the work in the recursion. Indeed, it always produces all but one word, except that the first letter from the original word is missing. Example: </div>  <div><br></div>  <div>   given:          the recursion                           in the final result I want                    plus </div>  <div>  'X   "ATE"     "X" "TE" --> "XTE" "TXE" "TEX"     "AXTE" "ATXE" "ATXE" "ATEX"           "XATE" </div>  <div><br></div>  <div>Given the recursive result (the list of words that are too short by the first letter in the orginal word) can you design a function that adds this letter (no matter what it is) to the front of all these words you have gotten back? </div>  <div><br></div>  <div>DONE? </div>  <div><br></div>  <div>After that: what is missing? </div>  <div><br></div>  <div>-- Matthias</div>  <div><br></div>  <div><br></div>  <div><br></div>  <div><br></div><br>  <div>On Mar 28, 2008, at 11:51 AM, Cooke Kelsey wrote:<br class="Apple-interchange-newline">  <blockquote type="cite">  <div>OK, that helps me a little.  If I insert "cons (first word)," then I can rebuild the word:</div>  <div> </div>  <div>(define (cons-function word)<br>  (cond<br>    [(empty? (rest word)) word]<br>    [else (cons (first word) (cons-function (rest word)))]))</div>  <div> </div>  <div>(cons-function (list 'A 'T 'W)) = (list 'A 'T 'W)</div>  <div> </div>  <div>The problem is how to add this to a shrinking function:</div>  <div> </div>  <div>(define (shrinking-function s word)<br>  (cond<br>    [(empty? (rest word)) empty]<br>    [else (list (append (list s) word) (shrinking-function s (rest word)))]))<br></div>  <div>(This shrinking function isn't exactly what I want, but at least it gives me (list 'X 'A 'T 'W) and (list 'X 'T 'W)).</div>  <div> </div>  <div>So I append them together: </div>  <div> </div>  <div>(append (cons-function (list 'A 'T 'W)) (shrinking-function 'X (list 'A 'T 'W)))</div>  <div> </div>  <div>And I get this:</div>  <div> </div>  <div>(list (list 'X 'A 'T 'W) (list (list 'X 'T 'W) empty)) (list 'A 'T 'W (list 'X 'A 'T 'W) (list (list 'X 'T 'W) empty))</div>  <div> </div>  <div>Garbage!</div>  <div> </div>  <div>As a last resort, I try to combine cons and shrinking functions together:</div>  <div> </div>  <div>(define (cons+shrinking-function s word)<br>  (cond<br>    [(empty? (rest word)) word]<br>    [else (append (cons (first word) (cons+shrinking-function 'X (rest word))) (list s) (rest word))]))</div>  <div> </div>  <div>(cons+shrinking-function 'X (list 'A 'T 'W)) = (list 'A 'T 'W 'X 'W 'X 'T 'W)</div>  <div> </div>  <div>It looks kind of nice, but it is even further from the expected result.</div>  <div> </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">  <div><br></div>  <div>How about (cons 'A (list 'X 'T)) = (list 'A 'X 'T)</div>  <div><br></div>  <div><br></div>  <div><br></div><br>  <div>On Mar 28, 2008, at 10:53 AM, Cooke Kelsey wrote:<br class="Apple-interchange-newline">  <blockquote type="cite">(append (list 'A) (list 'X 'T)) = (list 'A 'X 'T)<br><br><b><i>Matthias Felleisen &lt;<a href="mailto:matthias@ccs.neu.edu">matthias@ccs.neu.edu</a>></i></b> wrote:   <blockquote class="replbq" style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #1010ff 2px solid">  <div><br></div>  <div>Here is a definition of 'adding in the missing element': </div>  <div><br></div>  <div>* 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? </div>  <div><br></div>  <div>* X = (list 'X 'T) and 'A --> I want (list 'A 'X 'T). How do I do that? </div>  <div><br></div>  <div>-- Matthias</div>  <div><br></div></blockquote>  <div><br class="khtml-block-placeholder"></div>  <hr size="1">  Be a better friend, newshound, and know-it-all with Yahoo! Mobile. <a href="http://us.rd.yahoo.com/evt=51733/*http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ">Try it now.</a></blockquote></div><br></blockquote><br>  <div><br class="khtml-block-placeholder"></div>  <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></blockquote></div><br></blockquote><br>  <div><br class="khtml-block-placeholder"></div>  <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></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><div>       <br class="khtml-block-placeholder"></div><hr size="1">Special deal for Yahoo! users &amp; friends - <a href="http://us.rd.yahoo.com/evt=47521/*http://tc.deals.yahoo.com/tc/blockbuster/text3.com ">No Cost. Get a month of Blockbuster Total Access</a> now</blockquote></div><br></body></html>