CS 307: Using DrScheme

On using DrScheme

DrScheme, written at Rice University, is an implementation of Scheme that runs on Windows PC's, Mac's, Linux, and other platforms. It has a relatively friendly user interface. This document describes some basic steps for running DrScheme. Consult the on-line documentation for additional information.

These note were adapted from notes from Gordon Novak's notes.

Downloading DrScheme

Interaction with DrScheme:

DrScheme will open a double window. The top window is for program code, and the bottom window is the interaction window for executing code.

A good way to use DrScheme is to use the top half of the window (the Definitions window) to input your functions; be sure to save your definitions to a file frequently. When you press the Execute button, DrScheme will restart and read in your function definitions. You can test your definitions by typing in test calls in the lower half of the window (the Interactions window).

Under the File menu in the menu bar at the top are commands:

Executing Expressions: First, load your programs by clicking the Execute button (green arrow) above the top window. This will read in, check, and compile your programs. If there are problems, it will tell you. You can also use (load "myfile.scm") in the Interactions window to load a file.

Type in an expression at the > prompt in the lower Interaction window. The expression may extend over multiple lines. The expression will be executed when you type Return with balanced parentheses. Use the Interaction window to test programs, but always make files containing your programs rather than just typing them in to the interpreter.

Documentation: On-line documentation is available under Help. There is lots of useful information about Scheme and programming.

Editing: DrScheme helps balance your parentheses; this is very important. The Tab key can be used to space over th beginning of a line to the proper position based on its level of parentheses; if you change your program, Tab will move a line to its correct position. Using a good, indented style will help you avoid errors. Several keys are defined under the Edit menu for editing; see the on-line documentation for others.

  1. Backspace deletes the character to the left of the cursor (the character just typed).

  2. Edit-Cut (Ctrl+X) Select a section of text on the screen by placing the cursor at the start of the text, pressing and holding down the left mouse button, and dragging the mouse to highlight the desired area of text. Then select Cut to remove (and save) the text.

  3. Edit-Copy (Ctrl+C) Select a section of text as described for Cut. Copy works the same way, but does not remove the selected text.

  4. Edit-Paste (Ctrl+V) Place the cursor where you want the text to go and click the mouse to set the insertion point. Then select Paste to deposit the saved text at that point.

Printing Graphics: It is possible to print the graphics window by clicking the mouse in the graphics window to expose it, then entering Alt-PrintScreen; this will copy the contents of the graphics window to the clipboard. Then start Paint using Start-Programs-Accessories-Paint, use Paste to paste the clipboard into Paint, then Print from Paint.

Incremental Testing: If you write a big program and test the whole thing, chances are that it will not work the first time; it is likely to be hard to figure out why it didn't work, since there are many parts and there may be several errors. Scheme makes it easy to give some test data to each component, which lets you test that component alone and find errors much more easily. Make sure that the components work before trying the whole thing.

Tracing Functions: A great way to see what is happening inside your program is to trace it; this will print the input each time a function is entered and its output upon exit. Use the command (trace function) to trace a function and (untrace function) to turn it off. TO load the tracking package, evaluate (require (lib "trace.ss")).

Getting Out of Trouble: Your program may not work correctly the first time! Here are some kinds of trouble and ways to get out:

  1. If you enter, for example, (+ 3 'p) the system will complain that p is not a number and highlight the part of your code that caused the error. Click the function name to get documentation; click the bug to get a backtrace.

  2. Infinite Loop: If your program begins executing and doesn't quit, there is a good chance that you have an infinite loop. You can stop the execution with the Break button (Stop sign).