<div dir="ltr">Hi Carl,<div><br></div><div>Thank you very much for your kind feedback. I agree with you that having a single data structure will make the solution simpler. Let me ponder over that and see what I can come up with. </div>
</div><div class="gmail_extra"><br clear="all"><div><br>Thanks,<br>Jingjing</div>
<br><br><div class="gmail_quote">On Tue, Sep 24, 2013 at 9:10 AM, Carl Eastlund <span dir="ltr"><<a href="mailto:cce@ccs.neu.edu" target="_blank">cce@ccs.neu.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><div><div>Jingjing,<br><br></div><div>The new code you've written only follows the HtDP design recipe superficially.<br></div><div><br></div>First of all, none of your contracts actually tell me what the valid inputs and outputs of each function are. For instance, the contract for <span>build-position-to-neighbor</span> is:<br>
<br> <span>(listof lists) -> (hashof position to neighbors)<br><br></span></div><div><span>But this suggests to me that I could call it like this:<br><br></span></div><div><span> (build-position-to-neighbor (list (list "the" 'first "list") (list "list" 'number 2) (list (list (list)))))<br>
<br></span></div><div><span>After all, that argument is a list of lists. Nevertheless, that doesn't seem like what build-position-to-neighbor should actually accept. Your contracts need to be based on explicit data definitions. Descriptive phrases like "list of lists" or "hash of position to neighbors" are not precise enough.<br>
<br></span></div><div><span>Second, I think if you write data definitions for this program, you'll find something surprising: there are at least two different data definitions for a boggle board hidden in your functions. For a program that's all about processing a boggle board, you in fact manipulate many different kinds of lists and hash tables. It would be simpler, and more in the style of HtDP, to write a single data definition for a boggle board, and use that data definition for every function that operates on a boggle board.<br>
<br></span></div><div><span>Finally, your test cases are not particularly exhaustive. When testing a function, you should start with the smallest possible example. Write at least one base case test, at least one test for a single step beyond the base case, and at least one test larger than that. That way, when a test goes wrong, you don't just know that the function is broken, you have some idea how and why it is broken.<span class="HOEnZb"><font color="#888888"><br>
</font></span></span></div><div class="gmail_extra"><span class="HOEnZb"><font color="#888888"><br clear="all"><div>Carl Eastlund</div></font></span><div><div class="h5">
<br><div class="gmail_quote">On Tue, Sep 24, 2013 at 11:18 AM, Jingjing Duan <span dir="ltr"><<a href="mailto:duanjingjing@gmail.com" target="_blank">duanjingjing@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">Hi Carl,<div><br></div><div>I've cleaned up the code a bit and added tests to all the functions. Do you mind taking another look? Don't hesitate to give comments even if they are trivial. The more the better. I'm a total scheme/racket beginner. Thanks.</div>
<div><br></div><div><a href="https://github.com/jduan/boggle_scheme/blob/master/boggle.rkt" target="_blank">https://github.com/jduan/boggle_scheme/blob/master/boggle.rkt</a><br></div><div><br></div><div>In the mean time, I'm going to take a look at Jay McCarthy's solution. I didn't want to look at his code before because I didn't want his code to affect my refactoring.</div>
</div><div class="gmail_extra"><br clear="all"><div><br>Thanks,<br>Jingjing</div><div><div>
<br><br><div class="gmail_quote">On Sat, Sep 21, 2013 at 9:14 PM, Carl Eastlund <span dir="ltr"><<a href="mailto:cce@ccs.neu.edu" target="_blank">cce@ccs.neu.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">Looking forward to to your followup!<span><font color="#888888"><br></font></span><div class="gmail_extra"><span><font color="#888888"><br clear="all"></font></span><div><span><font color="#888888">Carl Eastlund<br>
</font></span><br></div><div>P.S. copying to the mailing list so everyone's in the loop.<br></div><div><div>
<br><div class="gmail_quote">On Sat, Sep 21, 2013 at 8:25 PM, Jingjing Duan <span dir="ltr"><<a href="mailto:duanjingjing@gmail.com" target="_blank">duanjingjing@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><div class="gmail_extra">Hi Carl,</div><div class="gmail_extra"><br></div><div class="gmail_extra">Thanks for your great feedback. Let me try to rewrite the code, this time by following the recipes from HTDP. Will send out another email once I'm ready!</div>
<div class="gmail_extra"><div><br>Thanks,<br>Jingjing</div><div><div>
<br><br><div class="gmail_quote">On Sat, Sep 21, 2013 at 10:25 AM, Carl Eastlund <span dir="ltr"><<a href="mailto:cce@ccs.neu.edu" target="_blank">cce@ccs.neu.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><div>On Sat, Sep 21, 2013 at 12:09 PM, Jingjing Duan <span dir="ltr"><<a href="mailto:duanjingjing@gmail.com" target="_blank">duanjingjing@gmail.com</a>></span> wrote:<br></div><div class="gmail_extra">
<div class="gmail_quote"><div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi,<div><br></div><div>I've been reading HTDP and I'm about half way
through. To apply what I've learned in the book to a bigger exercise, I
decided to write a boggle solver.</div><div><br></div>
<div>You can find the code here: <a href="https://github.com/jduan/boggle_scheme/blob/master/boggle.rkt" target="_blank">https://github.com/jduan/boggle_scheme/blob/master/boggle.rkt</a></div><div><br></div><div>Any feedback is greatly appreciated. I'm specifically looking for feedback on:</div>
<div><br></div><div>1. Did I break the problem into right components?</div><div>2. How can I make the code more idiomatic?</div></div></blockquote><div><br></div></div><div>If you're halfway through HtDP, you should know the value of data definitions, contracts, and test cases. I don't see any of those in your program. That makes it very hard to tell what's going on in the code, and whether it's doing the right thing. Adding them after the fact should improve your code's readability. Adding them earlier -- during the design process of the code itself -- helps break things down into components in a natural way.<br>
</div><div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">3.
Why is code so slow? It can take minutes to solve a 4 by 4 board. The
same board can be solved by a ruby program I wrote in much less time,
like a few seconds. I know recursive functions are a big reason but is
there anything?<br clear="all"></div></blockquote><div><br></div></div><div>"Recursive functions" have nothing to do with the kind of slowdown you're seeing. Your program is simply doing too much work. Start adding simple test cases for your functions and you may start to get a clearer idea of where a lot of the work is being done. The process of adding test cases may also suggest simpler ways to structure your program, both in terms of making it more idiomatic and in terms of doing less work.<br>
<br></div>You might get a lot out of restarting this boggle exercise from the top down, starting with the function find-all-words and going through the design recipe step by step. You may be surprised how different the result is from what you've written, and how much more natural the solution you get is. In my own experience, it is also a much quicker process than taking something written as a whole without the design steps, and trying to add them in after the fact.<br>
<div><br></div><div>However you proceed, please feel free to share your results and any other questions you have with the list. We love hearing about stuff like this!<br></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">
<div>Thanks,<br>Jingjing</div></div></blockquote><div><br></div><div>No problem. Glad to see you're interested in HtDP and Racket! Good luck!<span><font color="#888888"><br><br></font></span></div><span><font color="#888888"><div>
--Carl <br></div></font></span></div></div></div>
</blockquote></div><br></div></div></div></div>
</blockquote></div><br></div></div></div></div>
</blockquote></div><br></div></div></div>
</blockquote></div><br></div></div></div></div>
</blockquote></div><br></div>