<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:&nbsp;How To Design Programs, 2nd Edition (Chapter 4,&nbsp;Section 4.5.1).<br></blockquote><blockquote type="cite">[...]</blockquote><blockquote type="cite">However, the code feels .... wrong. As if I didn't&nbsp;do&nbsp;it the Scheme way. It's like writing C with classes and not idiomatic&nbsp;C++. It&nbsp;works, but it's wrong.<br><br>So any tips, hints, pointing in the right direction, would be greatly&nbsp;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 -&gt; list-of-word</div></div><div><div>; create combinations of word in list-of-word</div></div><div><div>(define&nbsp;(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?" &nbsp;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&nbsp;<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)". &nbsp;But what does that mean? &nbsp;The purpose statement speaks as though <b>word</b> is a parameter, but it's not -- you have <b>ins-ltr</b>&nbsp;and <b>a-low</b>. &nbsp;Also, what does it mean by "combinations"? &nbsp;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: &nbsp;Ask yourself what the function must produce from&nbsp;<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>&nbsp;and&nbsp;<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&nbsp;</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>&nbsp;in <b>insert-everywhere/in-one-word</b>. &nbsp;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&nbsp;<b>insert-everywhere/in-one-word</b>. &nbsp;Specific data is <i>almost always</i>&nbsp;easier to think about than abstract names. &nbsp;At very least, make a test case for a 1-letter word <b>w1</b>&nbsp;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>&nbsp;and&nbsp;<b>(insert-everywhere/in-one-word a-1str (rest a-word))</b>&nbsp;are. &nbsp;Compare those data to your test cases' desired results, since those results are what <b>create-combinations</b>&nbsp;must produce from those two pieces of data. &nbsp;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>&nbsp;must do, then great! write a purpose statement for it (and perhaps change the name to something nicely descriptive of what you want). &nbsp;If not, try making a larger test case (e.g., a word <b>w</b>&nbsp;such that <b>(rest w)</b>&nbsp;is your two-letter word from earlier), and repeat the process. &nbsp;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. &nbsp;Your intuition is good. &nbsp;Keep at it.</div><div><br></div><div>Best,</div><div>jmj</div><div><br></div></body></html>