If there are any questions that aren't addressed here, let me know and I'll update this document.
whuang@cs.rpi.edu; email
Using emacs
I'm now recommending that you use gnu-emacs to write your Scheme code
because a full version of gnu-emacs is more user-friendly than Edwin.
If your are running on UNIX, you can run Scheme as an inferior process
from emacs and use Edwin only when you need the debugger. If you are
running under Windows, then you should use Edwin to interact with
Scheme and for minor editing.
Here are a few useful links:
For some assignments, you will probably want to start Scheme with more memory. In UNIX, you can just give some additional command line switches. In Windows, you should probably create some new shortcuts based on the ones that already exist in your start menu. You can edit the shortcuts to add the following command line switches.
Starts Scheme with a larger heap (about 3-4 times larger than usual).
Starts Scheme with a heap of 4000K words. For reference, the -large switch is equivalent to about 1200K or 1300K words.
You can get information on the amount memory that Scheme is using
with the command (print-gc-statistics).
Debugging Scheme code
Debugging is a learned art. Part of that art is learning how to use
available tools to see what's going on in your code. Here are a few
tools/suggestions:
Scheme is an interpreted language; this means that it's easy to run small parts of your program to make sure that they're doing the right thing.
The Edwin debugger will show you lists of subproblems and reductions (see the MIT Scheme User's manual for a more detailed explanation of this). It will also let you evaluate expressions in the environments for these subproblems and reductions.
Don't expect to understand everything that appears on the screen in the debugging window. It can be a bit cryptic, so you'll have to look carefully for information that you can use and that makes sense to you.
To start, use the debugger to find out where in your code the error is being generated and what inputs cause that error.
Tracing procedures is a powerful mechanism for debugging. You can trace a function with the command:
(trace function-name)Then, whenever this function is called, it will print a message to the screen showing what arguments it was called with. When the procedure returns, it will print a message showing what value that call returned.
To turn off tracing, use the command:
(untrace function-name)Or, to turn off all tracing, simply:
(untrace)When you reload a file, all the procedures will be reset to being untraced. You can put these commands in your Scheme file while you are developing your code. (But take them out before you submit your file!)
This is the old standby, perhaps the most straightforward approach to debugging but the least sophisticated. The Edwin debugger is good for seeing what causes an error, but is harder to use for interactively debugging your code as it runs (i.e. setting breakpoints and such). Here is an example:
(define (my-function a b c)
(display "\nMy function was called with the arguments: ")
(map display (list a b c)) ; be careful with this because on different
; implementations, the arguments might be
; evaluated in different order, giving you
; the values reversed!
(newline)
(if (= a b)
(begin
(display "\nWell, it turns out that A and B are the same\n")
(my-fun-helper b c))
(begin
(display "\nOops, A and B are different!\n\n)
(my-fun-helper a b))))