<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 6:22 PM, Cooke Kelsey wrote:</html><br class="Apple-interchange-newline"><blockquote type="cite"><div>Hi, I've made some progress but no jackpot yet...</div></blockquote><div><br></div>This is huge progress. Let's roll this up backwards: (see numbers)</div><div><br></div><div><br><blockquote type="cite"> <div><span class="Apple-style-span" style="-webkit-text-stroke-width: -1; ">Here are the tables with all of the values, as you suggested:</span></div> <div> </div> <div>First Table: </div></blockquote><div><br></div><div>ROW 1:</div><br><blockquote type="cite"><div> <br> s | word | (first word) | (insert-in-single-word s (rest word)) | expected result for (insert-... s low)<br> --------------------------------------------------------------------------------------------------------<br> 'X |(list 'A 'T)| 'A | (list (list 'X 'T) (list 'T 'X)) | (list (list 'X 'A 'T) (list 'A 'X 'T) (list 'A 'T 'X))<br> <br> Table for Recursive Case:</div></blockquote><div><br></div><div>ROW 2: </div><br><blockquote type="cite"><div><br> <br> s | word | (first word) | (insert-in-single-word s (rest word)) | expected result for (insert-... s low)<br> --------------------------------------------------------------------------------------------------------<br> 'X |(list 'T)| 'T | (list 'X) | (list (list 'X 'T) (list 'T 'X))<br></div> <div> </div></blockquote><div><br></div><div><br></div><div>From ROW 2: you get a list of ONE word ("X") back from the recursive call. But you want TWO words altogether and the word is missing the letter T, the first of the current word. The word that is missing is "XT" which is the old word prefixed with X, the letter to be inserted. </div><div><br></div><div>From ROW 1: you get a list of TWO words ("XT" "TX") back from the recursive call. But you want THREE and the words are missing the letter A, the first of the current word. The word that is missing is "XAT" which is the old word prefixed with X, the letter to be inserted. </div><div><br></div><blockquote type="cite"> <div>After examining the tables, I tried a couple of new ways to get the results in the last column. </div></blockquote><div><br></div>Do my descriptions help? If not, try the following input: "ATT". What is the expected result? What is first? What's the recursive result? Etc. </div><div><br></div><div>Perhaps you also want to think about how the words you get back from the recursion go into the final result. </div><div><br></div><div>;; --- </div><div><br></div><div>Don't try to code it up. Try to think it through first and come up with a description of WHAT has to happen to combine all these values properly. THEN turn this into a function with the design recipe. </div><div><br></div><div>-- Matthias</div><div><br></div><div><br></div><div><br><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><div><br></div><div><br></div><div><br></div><div><br></div><br><blockquote type="cite"><div> </div> <div> </div> <div>The easiest way was simply to append the letters in order, so that X, AT-->XAT, AXT ATX </div> <div> </div> <div>(define (insert-in-single-word2 s word)<br>(list (append (list s) word) (append word (list s)) (append (list (first word)) (list s) (rest word))))</div> <div> </div> <div>This doesn't have any recursive part, so it only works on 3 letter words.</div> <div> </div> <div>When I tried to insert a recursive part, no matter how I arranged the parts, I always lost letters. </div> <div> </div> <div>For instance, the definition below results in: X,AT-->XAT, ATX, X</div> <div> </div> <div>(define (insert-in-single-word s word)<br> (cond<br> [(empty? (rest word)) empty]<br> [else (list (append (list s) word) (append word (list s)) (append (list s) (insert-in-single-word s (rest word))))]))<br></div> <div><br><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"> <div><br>On Mar 27, 2008, at 3:15 PM, Cooke Kelsey wrote:<br><br>> (1) At this point it becomes critical to spell out the (list ...) <br>> stuff, i.e., to turn the example into full-fledged Scheme data. <br>> Small step.<br>><br>> (.......which Scheme displays as (cons (cons 'X (cons 'A (cons 'T <br>> empty))) (cons (cons 'A (cons 'X (cons 'T empty))) (cons (cons 'A <br>> (cons 'T (cons 'X empty))) empty)))....)<br><br>I recommend raising the language level to Beginner with List ..<br><br><br>> (4) And before you complete the template build a table just like <br>> the one above for the recursive case.<br>><br>> First Table:<br>><br>> s | word | (first word) | (insert-in-single-word s (rest <br>> word)) | expected result for (insert-... s low)<br>> ---------------------------------------------------------------------- <br>> ----------------------------------<br>> 'X |(list 'A 'T)| 'A | (insert-in-single-word s <br>> (list 'T) | (list (list 'X 'A 'T) (list 'A 'X 'T) (list 'A 'T 'X))<br><br><br>What is the VALUE of (insert-in-single-word s (list 'T) ) ? The <br>purpose statement tells you!</div> <div> </div> <div><br><br>> Table for Recursive Case:<br>><br>> s | word | (first word) | (insert-in-single-word s (rest <br>> word)) | expected result for (insert-... s low)<br>> ---------------------------------------------------------------------- <br>> ----------------------------------<br>> 'X |(list 'T)| 'T | (insert-in-single-word s empty <br>> | (list (list 'X 'T) (list 'T 'X))<br><br>What is the VALUE of (insert-in-single-word 'X empty) ? The purpose <br>statement tells you!</div> <div> </div> <div><br>> I feel I am getting closer to the answer. The second table <br>> suggest to me that there is something about recurring down to 2 <br>> letters and then appending the rest on.....except that I lost the <br>> rest of the letters.<br><br>Almost! You need to actually determine the value of these expressions <br>not just write down the expressions to make the leap. You're almost <br>there.<br><br>And don't forget: if the leap is to large, you may need yet another <br>helper function.<br><br>-- Matthias<br><br><br><br></div></blockquote><br><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></body></html>