<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">
<br><div><html>On Mar 28, 2008, at 9:03 PM, Cooke Kelsey wrote:</html><br class="Apple-interchange-newline"><blockquote type="cite"><div>Here's an answer to your question:</div>  <div> </div>  <div>Q: "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></blockquote><div><br></div><div>NO! NO! </div><div><br></div><div>Look at the table for a call to insert-everywhere/one-word with 'X and (list 'A 'T). &lt;&lt;--- original call </div><div><br></div><div> If you now recursively call </div><div><br></div><div> * (insert-everywhere/one-word s (rest word)) and get </div><div>   (list (list 'X 'T) </div><div>          (list 'T 'X)) </div><div><br></div><div>and then you call </div><div><br></div><div> *  (add-letter-to-all (first word) ... the above ..) you get </div><div>     (list (list 'A 'X 'T) </div><div>            (list 'A 'T 'X))</div><div><br></div><div>What do you want for the result of the original call? </div><div>How can you add this to what you have so far? </div><div>(10 keystrokes)</div><div><br></div><div>That's the question I raise. -- Matthias</div><div><br></div><div><br></div><div><br></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>A: What's missing is the second letter, the third, etc.   </div>  <div> </div>  <div>That is, I can add "W" to a list:</div>  <div> </div>  <div> (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>But I also need "A" "T" E" "R" to be added, incrementally:</div>  <div> </div>  <div> (list 'w 'x 'a 't 'e 'r)<br> (list 'w 'a 'x 't 'e 'r)<br> (list 'w 'a 't 'x 'e 'r)<br> (list 'w 'a 't 'e 'x 'r)</div>  <div> </div>  <div>Mark suggested that I look carefully at the table and see how I can "rearrange" the items in the columns to produce the result.  Everyone seems to suggest that the answer is found in that table, so I have been copying it and drawing arrows between the letters.  </div>  <div> </div>  <div>At this point the solution seems to be to create a second shrinking list of (rest words), flip it around backwards and then merge it into the original list.  I've written some functions to attempt this, but nothing near the expected result.  </div>  <div> </div>  <div>Marco has suggested that my entire approach is wrong, that I should build words correctly from the beginning instead of adding missing letters.  </div>  <div> </div>  <div>I'm going to begin again from scratch and pay closer attention to the template and contracts.</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>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>On Mar 28, 2008, at 5:35 PM, Cooke Kelsey wrote:<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></blockquote></div></blockquote><div>       <br class="khtml-block-placeholder"></div><hr size="1">You rock. That's why Blockbuster's offering you <a href="http://us.rd.yahoo.com/evt=47523/*http://tc.deals.yahoo.com/tc/blockbuster/text5.com ">one month of Blockbuster Total Access</a>, No Cost.</blockquote></div><br></body></html>