<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br>On Apr 27, 2013, at 10:35 PM, Da Gamer wrote:<br><br><blockquote type="cite">First, I'm working on problem: How To Design Programs, 2nd Edition (Chapter 4, Section 4.5.1).<br></blockquote><blockquote type="cite">[...]</blockquote><blockquote type="cite">However, the code feels .... wrong. As if I didn't do it the Scheme way. It's like writing C with classes and not idiomatic C++. It works, but it's wrong.<br><br>So any tips, hints, pointing in the right direction, would be greatly appreciated.<br></blockquote><div><br></div>[In the following, I'm using text from your first solution, but what I'm saying applies equally well to your second solution.]<div><br><div>It looks like the problem you're up against is that, beyond insert-everywhere/in-one-word, the function specifications are vague:</div><div><br></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><div>; 1-str list-of-word -> list-of-word</div></div><div><div>; create combinations of word in list-of-word</div></div><div><div>(define (create-combinations ins-ltr a-low) ...)</div></div></blockquote><div><br></div><div>One of the questions we ask in the Design Recipes is, "What is the result of the recursive call producing?" Here, for example, the recursive call is</div></div><div><br></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><span class="Apple-style-span" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', monospace, serif; font-size: 12px; line-height: 21px; "><span class="br0" style="color: rgb(102, 204, 102); ">(</span></span>create<span class="sy0" style="color: rgb(102, 204, 102); ">-</span>combinations ins<span class="sy0" style="color: rgb(102, 204, 102); ">-</span>ltr <span class="br0" style="color: rgb(102, 204, 102); ">(</span>rest a<span class="sy0" style="color: rgb(102, 204, 102); ">-</span>low<span class="br0" style="color: rgb(102, 204, 102); ">)</span><span class="br0" style="color: rgb(102, 204, 102); ">)</span></div></blockquote><div><br></div><div>and according to the purpose statement, it could be said to produce "combinations of word in (rest a-low)". But what does that mean? The purpose statement speaks as though <b>word</b> is a parameter, but it's not -- you have <b>ins-ltr</b> and <b>a-low</b>. Also, what does it mean by "combinations"? This is not clear, and so you can clarify both by rewriting the purpose statement and choosing a more descriptive function name.</div><div><br></div><div>So, here is what I would recommend: Ask yourself what the function must produce from <span class="Apple-style-span" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', monospace, serif; font-size: 12px; line-height: 21px; "><span class="br0" style="color: rgb(102, 204, 102); ">(</span>first a<span class="sy0" style="color: rgb(102, 204, 102); ">-</span>word<span class="br0" style="color: rgb(102, 204, 102); ">)</span></span> and <span class="Apple-style-span" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', monospace, serif; font-size: 12px; line-height: 21px; "><span class="br0" style="color: rgb(102, 204, 102); ">(</span></span><span class="Apple-style-span" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', monospace, serif; font-size: 12px; line-height: 21px; ">insert</span><span class="Apple-style-span" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', monospace, serif; font-size: 12px; line-height: 21px; "><span class="sy0" style="color: rgb(102, 204, 102); ">-</span></span><span class="Apple-style-span" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', monospace, serif; font-size: 12px; line-height: 21px; ">everywhere</span><span class="Apple-style-span" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', monospace, serif; font-size: 12px; line-height: 21px; "><span class="sy0" style="color: rgb(102, 204, 102); ">/</span></span><span class="Apple-style-span" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', monospace, serif; font-size: 12px; line-height: 21px; ">in</span><span class="Apple-style-span" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', monospace, serif; font-size: 12px; line-height: 21px; "><span class="sy0" style="color: rgb(102, 204, 102); ">-</span></span><span class="Apple-style-span" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', monospace, serif; font-size: 12px; line-height: 21px; ">one</span><span class="Apple-style-span" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', monospace, serif; font-size: 12px; line-height: 21px; "><span class="sy0" style="color: rgb(102, 204, 102); ">-</span></span><span class="Apple-style-span" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', monospace, serif; font-size: 12px; line-height: 21px; ">word a</span><span class="Apple-style-span" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', monospace, serif; font-size: 12px; line-height: 21px; "><span class="sy0" style="color: rgb(102, 204, 102); ">-</span></span><span class="Apple-style-span" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', monospace, serif; font-size: 12px; line-height: 21px; ">1str </span><span class="Apple-style-span" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', monospace, serif; font-size: 12px; line-height: 21px; "><span class="br0" style="color: rgb(102, 204, 102); ">(</span></span><span class="Apple-style-span" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', monospace, serif; font-size: 12px; line-height: 21px; ">rest a</span><span class="Apple-style-span" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', monospace, serif; font-size: 12px; line-height: 21px; "><span class="sy0" style="color: rgb(102, 204, 102); ">-</span></span><span class="Apple-style-span" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', monospace, serif; font-size: 12px; line-height: 21px; ">word</span><span class="Apple-style-span" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', monospace, serif; font-size: 12px; line-height: 21px; "><span class="br0" style="color: rgb(102, 204, 102); ">)</span></span><span class="Apple-style-span" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', monospace, serif; font-size: 12px; line-height: 21px; "><span class="br0" style="color: rgb(102, 204, 102); ">)</span></span> in <b>insert-everywhere/in-one-word</b>. And don't be satisifed until you have an answer that contains no vagueness at all.</div><div><br></div><div>Now, answering that question is probably not easy, and this is where the rest of the Design Recipe is useful:</div><div><br></div><div>1) Write a couple of test cases for <b>insert-everywhere/in-one-word</b>. Specific data is <i>almost always</i> easier to think about than abstract names. At very least, make a test case for a 1-letter word <b>w1</b> and another for a 2-letter word <b>w2</b>, such that <b>w1</b> is <b>(rest w2)</b>.</div><div><br></div><div>2) In those test cases, identify what <b>(first a-word)</b> and <b>(insert-everywhere/in-one-word a-1str (rest a-word))</b> are. Compare those data to your test cases' desired results, since those results are what <b>create-combinations</b> must produce from those two pieces of data. Use these data to make a test case for <b>create combinations</b>.</div><div><br></div><div>3) If you can come up with a plain-English description of what <b>create-combinations</b> must do, then great! write a purpose statement for it (and perhaps change the name to something nicely descriptive of what you want). If not, try making a larger test case (e.g., a word <b>w</b> such that <b>(rest w)</b> is your two-letter word from earlier), and repeat the process. Eventually you will most likely see a pattern you can describe.</div><div><br></div><div>This is a tough problem, but taking the time to find the simple solution is worth it IMO. Your intuition is good. Keep at it.</div><div><br></div><div>Best,</div><div>jmj</div><div><br></div></body></html>