CS 307: 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.

Please do not send messages about DrScheme to Rice University; send them to your TA instead. The TA's will contact Rice if necessary.

Downloading DrScheme

Also get the file initdr.scm from ftp.cs.utexas.edu/pub/novak/cs307/ A good place to put it is in the directory C:\ProgramFiles\Plt (where DrScheme.exe is).

Starting DrScheme:

Start DrScheme on the lab PC's from the Start button using the menu sequence Programs, Programming, PLT Scheme, DrScheme.

DrScheme can also be started from the directory C:\ProgramFiles\Plt by double-clicking on its red-and-blue "lambda" icon.

The language level you should be using is called Graphical Full Scheme (MrEd). Lab machines start up this way. If your DrScheme does not show this level, click the Language button at the top, then Choose Language. Set the language level to Full Scheme. Then click the Execute button to reset the language level; it should remain set thereafter. (If you try loading the init file initdr.scm before setting the language level, it will give an error.)

Before loading files, you will need to set the directory path, e.g.:

(current-directory "c:/program files/plt/")

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).

You should begin your file with the following:

     ; Your Name       CS 307   Assignment n      Date
     (current-directory "c:/program files/plt/")  ; or other path
     (load "initdr.scm")

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.

Disks: You should save all of your programs on disks; some programs will be used again or expanded in later assignments. An experienced computer scientist has a healthy paranoia about magnetic media and keeps backup copies of things that are important. ``The dog ate my disk'' is not a valid excuse; you should have a backup copy. Remember that all your files will be erased from the lab computer when you logout, so save them to disk first.

Editing: DrScheme helps balance your parentheses; this is very important. The Tab key can be used to space over the 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.

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).
CS 307