Followup for Tutorial 6 ======================= Bloated Buffers --------------- With the last project, one student ran into an initially-cryptic error message from Edwin boiling down to some string buffer being full. The problem was that the *transcript* buffer was too full. It had run out of memory since so many things had been evaluated. The solution was to save, exit Scheme, the restart. Vector Diversity ---------------- Vectors CAN hold objects of different types. Consider the following example from the reference manual (http://sicp.csail.mit.edu/Spring-2005/manuals/scheme-7.5.5/doc/scheme_9.html#SEC85): (let ((vec (vector 0 '(2 2 2 2) "Anna"))) (vector-set! vec 1 '("Sue" "Sue")) vec) => #(0 ("Sue" "Sue") "Anna") Pass-by-value/pass-by-reference ------------------------------- Warning: if you don't know what the heading for this note means, please go to the next heading. This is a question about how Scheme relates to other languages. In one tutorial session, some students asked about whether Scheme is pass-by-value or pass-by-reference. The quick answer is: it doesn't matter. The explanation is relatively easy to show with the environment model, but I don't want to get ahead of the class. If you'd like to see an explanation that still skirts around the environment model, consider looking at http://www.cs.oberlin.edu/classes/dragn/labs/param/param1.html#@l11 Debugging Tips -------------- I thought I'd write up some hints to use when working on the projects or other large blocks of code. * Scenario: I'm not sure how to debug o Go through lecture 7 again * Scenario: you hit M-o on your file and you get an error because you added an extra closing parenthesis somewhere. o Look in the transcript at the last result that actually worked. This should give you an idea about where to look. o Binary search: create a new buffer containing only the first half of your code. Run it. If it works, add half the remaining code. If it doesn't work, remove half the code you just added. Repeat the process until you find the problem. o Dr. Scheme helps you hunt them down using highlighting * Scenario: you spend hours and hours hunting down tiny bugs o Make sure you understand what you're trying to do o Add assert statements to your procedures to make sure they have valid arguments. o Add display statements to print out intermediate results in buggy procedures * Scenario: copying-and-pasting test case results is a pain o Write and test all of your code as normal. When you're ready to insert your results, copy all of your code into the Scheme buffer. For each expression: + Go to the end of the line + Type C-x C-e to evaluate the line + If the line is a procedure definition, type C-k C-k C-k to get rid of the extra results o asserts: When you know the actual desired answer, consider writing some assert procedures that will do nothing if you get the expected result or generate an error for wrong results. See the solutions to tutorial problems for the last few weeks for examples. If you do this in a project, just tell me at the end of some assert block that everything tested out okay (assuming it did).