DrScheme
A User Manual
UBC
Edition
Copyright
notice
Copyright
©1996-99 PLT, Rice University
Modifications for the
Department of Computer Science in University of British Columbia made by
Michael Pang and David Lowe (August 2001)
Permission to make digital/hard copies and/or distribute this documentation for
any purpose is hereby granted without fee, provided that the copyright notice,
author, and this permission notice appear in all copies of this documentation
1 Introduction to DrScheme and this
document
DrScheme is a graphical environment for developing programs using the Scheme
programming language that is used for CPSC 124, CPSC 126, and CPSC 128. This document describes DrScheme for Unix
(and most also applies to DrScheme for Windows). You can run DrScheme on
Unix by running the command “drscheme”.
For more information on DrScheme, you can visit the official web site at http://www.cs.rice.edu/CS/PLT/packages/drscheme/.
The DrScheme interface is comprised of two main components: the interactions window and the definitions window. The interaction window allows you to "play" with Scheme. You can type in Scheme forms and get immediate results back from Scheme. The definition window allows the user to edit programs and send them to Scheme to be evaluated
2 The DrScheme Window
2.1 Anatomy of the DrScheme
Window
The DrScheme window has three parts: a row of
buttons at the top, two editing panels in the middle, and a status line at the
bottom.

|
Definitions
Window (DrScheme Editor) |
Lets user define Scheme programs. The above
figure shows a program that defines the function square. |
|
Interactions Window |
Evaluates Scheme expressions interactively. The Language line in the interactions
window indicates which primitives are available in the definitions and
interactions windows. The CS courses
at UBC use MrED. |
|
Buttons |
The button bar is a convenience. It contains
the following buttons: Save, Check Syntax, Execute, Break. The function of
these buttons will be explained below |
|
Menus |
The menu bar contains seven menu options: File,
Edit, Windows, Show, Language, Scheme, Help. Clicking on anyone of
these will produce a pop-up menu. These functions in these menus will
be explained below |
|
Status line |
Provides information about the current line and
position of the editing caret, whether the current file can be modified, and
whether DrScheme is currently evaluating any expression. The recycling icon
flashes while DrScheme is ``recycling'' internal resources, such as memory. |
The interaction window shares the same menu
and button with the definition window
and they have the same commands
2.1.1 Menu Buttons
|
Button |
Motion |
|
|
(define ...) |
A popup menu of names
defined in the definitions window. Selecting an item from the menu moves the
blinking cursor to the corresponding definition. |
|
|
Save |
Appears whenever the
definitions window is modified. Clicking the button saves the contents of the
definitions window to a file. The current name of the file appears to the
left of the Save button, but a
file-selection dialog appears if the file has never been saved before. |
|
|
Step |
Starts The Foot, which
shows the evaluation of a program as a series of small steps. Each evaluation
step replaces an expression in the program with an equivalent one using the
evaluation rules of DrScheme. Clicking Step opens a new window that contains
the program from the definitions window, plus three new buttons: Next,
Previous, and Home. The Step button
works only for programs using the Beginning Student language level. |
|
|
Check Syntax |
Checks the syntax of the program in the definitions window and colorizes keywords and primitive function names. It also enables pop-up arrows that show the relationship between variable declarations and their uses when the mouse cursor is moved over a variable. Modifying the program turns off the arrows until Check Syntax is clicked again. |
|
|
Execute |
Evaluates the program in
the definitions window and resets the interactions window. |
|
|
Break |
Interrupts an evaluation,
or beeps if DrScheme is not evaluating anything. For example, after clicking
Execute or entering an expression into the interactions window, click Break
to cancel the evaluation. Click the Break button once to try to interrupt the
evaluation gracefully; click the button twice to killing the evaluation
immediately. |
|
2.1.2 Loading Teachpacks
A teachpack extends the set of procedures that are built into a language in DrScheme. For example, a teachpack might extend the DrScheme language with a procedure for graphing. In your lab books, teachpacks are referred to as goodies. Other than the difference in extensions, the goodies mentioned in the lab book should have the same name as the teachpacks.
Most labs require having a Teachpack opened. To use the teachpack, select it through the Language > Add Teachpack... in the menu item. You will then need to navigate to the directory containing the appropriate teachpack. Clicking on “..” will move you up a directory. The Lab teachpacks are mostly in /cs/local/lib/pkg/drscheme-103/collects/ubc/

2.2 Window
Features
Here are key conventions used in following sections
|
C- <key> |
This means press the
Control key, hold it down and then press <key> and then release them both. For example: C-e
(Control-e) moves the blinking caret to the end of the current line. |
|
M- <key> |
Same as C- <key> , except with the Meta key. Depending on your
keyboard, Meta may be called “Left”, “Right” or have a diamond symbol, but
it's usually on the bottom row next to the space bar. M- <key> can also be performed as a two-character
sequence: strike and release the Escape
key, then strike <key> . Under Windows
and MacOS, Meta is only
available through the Escape key. |
|
<div align=right>Note:</div> |
On most keyboards, “<” and “>” are shifted characters. So, to get M-<, you actually have to type Meta-Shift-< That is, press and hold down both the Meta and Shift keys, and then strike “<” |
For more
information, please see Appendix A
2.2.1 Movement
|
Key |
Motion
|
|
¬ and ® |
These move the cursor one character to the left and right respectively |
|
and ¯ |
These move the cursor one line up or down respectively |
|
[Page Up] and [Page Down] |
These move the view in the
window up or down by a page |
|
M-f and M-b |
These move the cursor forward and backward one word respectively |
|
C-a |
This moves the cursor to the beginning of line (left) |
|
C-e |
This moves the cursor to the end of line (right) |
|
M-< and M-> |
These move the cursor to the beginning and end of the file respectively |
2.2.2 Editing
There are two main aspect of editing: adding characters and deleting characters.
2.2.1.1 Inserting Text
Adding characters is fairly trivial - just type in and they appear in the editor. The only special cases are control characters (characters where you hold down the [Control] or [Meta] at the same time as pressing something else). As noted earlier, many control characters are used as keyboard accelerators. This means that they cannot be entered into the body of the text. Generally this is not a problem (how often do you need to insert Control-G in your text?) Currently the editor does not allow you to enter control characters.
Another way to insert text is to paste text into the document. This is explained below in the section "Cutting, Copying and Pasting".
2.2.1.2 Deleting Text
There are many ways to delete text, for many
increments from single characters to blocks of text. Deleting blocks of text will be discussed below in section
"Cutting, Copying and Pasting"
Below is a table of keys and what type of deletion they perform.
|
Key |
Deletion Type |
|
[Backspace] and [Delete] and C-h |
These delete the character immediately before or after the cursor. |
|
C-d |
This deletes one character after the cursor |
|
M-[Delete] |
This deletes backward one word |
|
M-f and M-b |
These move the cursor forward and backward one word respectively |
|
C-a |
This moves the cursor to the beginning of line (left) |
|
C-e |
This moves the cursor to the end of line (right) |
|
M- < and M- > |
These move the cursor to the beginning and end of the file respectively |
2.2.1.3 Copying and Pasting
Selecting Text
It is also possible to insert and delete blocks of text. There are three ways to select a block of text:
1. Click on the left mouse button and drag the mouse in the direction that you want to select. The disadvantage of this is that this is limited to the visible page
2. Use Select All option to choose all the text in the file
3. Click the right mouse button to select the text between the mouse the cursor.
Copying and Cutting Text
After selecting, select Copy or Cut from the Edit window. Cut copies the selected text to the clipboard and deletes it from the window. Copy copies the selected text to the clipboard.
Pasting Text
There are three ways to insert a block of text. When a bock of text has been selected (in any X Windows application):
1. Use the middle mouse button to paste your text at the point where the mouse is when the button is pressed.
2. Press C-y to paste text at where the cursor is
Deleting Selected Text
Select Delete or Clear option from the Edit
menu and deletes the selected text.
2.2.2 File Management
Once you have written a file you may wish to save it (in fact after a few hours working on it you will definitely want to save it!) for editing later. You may also wish to load a previously saved file. This is all done using the editor's file handling capabilities.
About
AutoSave
When a file in an active DrScheme editor is modified but not saved, DrScheme saves the file to a special AutoSave file after five minutes (in case of a power failure or catastrophic error). If the file is later saved, or if the user exits DrScheme without saving the file, the AutoSave file is removed.
The AutoSave file is
saved in the same directory as the original file, and the AutoSave file's name
is generated from the original file's name with a pound sign (#) is added to
the start and end of the file's name. Then a number is added after the ending
pound sign, and then one more pound sign is appended to the name. The number is
selected to make the AutoSave filename unique.
An example of a AutoSave file is #mredauto#3#.
|
<div align=right>Note:</div> |
Although DrScheme has the AutoSave function, it is a good idea to SAVE YOUR FILES FREQUENTLY!!! |
2.2.2.1
Saving a File
The Save button appears whenever the definitions window is modified. Clicking the button saves the contents of the definitions window to a file. The current name of the file appears to the left of the Save button, but a file-selection dialog appears if the file has never been saved before.
You can also save from the File section in the menu bar:
|
Item in File section |
Function |
|
Save Definitions |
saves the program in the definitions window. If the program has never been saved before, a save-file dialog appears. |
|
Save Definitions As... |
opens a save-file dialog for choosing a destination file to save the program in the definitions window. Subsequent saves write to the newly-selected file. |
|
Item in File > Save Other section |
Function |
|
Save Definitions As Text... |
is like Save Definitions As..., but the file is saved in plain-text format. Subsequent saves also write in plain-text format. |
|
Save Interactions |
saves the contents of the interactions window to a file. If the interaction constants have never been saved before, a save-file dialog appears. |
|
Save Interactions As... |
opens a save-file dialog for choosing a destination file to save the contents of the interactions window. Subsequent saves write to the newly-selected file. |
|
Save Interactions As Text... |
is like Save Interactions As..., but the file is saved in plain-text format. Subsequent saves are write in plain-text format. |
Keyboard Shortcuts:
|
Key |
Function |
|
M-S or C-x
C-s (Press C-x then C-s) |
Saves the file under the current file name or prompts for a new one |
|
C-x
C-w (Press C-x then C-s) |
Saves the file under a new name |
If the file has not been named or the option is a Save As function, DrScheme will prompt you for a file name with a save-file dialog.

When you modify an existing file
in DrScheme and save it, DrScheme copies the old version of the file to a
special backup file if no backup file exists. The backup file is saved in the
same directory as the original file, and the backup file's name is generated
from the original file's name with a tilde (~) added to the end of the file's
name.
2.2.2.2 Opening a File
You can open a file from
the file section in the menu bar:
|
Item in File
section |
Function
|
|
Open... |
opens a find-file dialog for choosing a file to
load into a definitions window. |
2.2.2.3 Other Options in the File Menu
|
Item in File
section |
Function |
|
New |
creates a new DrScheme window. |
|
Open
Project... |
opens a saved project window. |
|
Open URL... |
opens a dialog for choosing a Uniform Resource
Locator (URL) to open in a new Help Desk window. |
|
Revert |
re-loads the file that is currently in the
definitions window. All changes since the file was last saved will be lost. |
|
Print
Definitions... |
opens a dialog for printing the current program in
the definitions window. |
|
Print
Interactions... |
opens a dialog for printing the contents of the
interactions window. |
|
Bring
project to the front |
brings the project window associated with this
window to the front. |
2.2.2.4 Closing Windows and Exiting
|
Item in File
section |
Function |
|
Quit |
exits DrScheme. |
|
Close |
closes this DrScheme window. If this window is the
only open DrScheme window, DrScheme quits. |
2.3 Advanced Features
2.3.1 Bracket Matching and Indenting
DrScheme's editor provides special support for managing parentheses in a program. When the blinking caret is next to a parenthesis, DrScheme shades the region between the parenthesis and its matching parenthesis. This feature is especially helpful when for balancing parentheses to complete an expression. Furthermore, if you type a closing parenthesis ``)'' that should match an opening square bracket ``['', the editor automatically converts the ``)'' into a ``]'' as it treats square brackets as parenthesis. DrScheme beeps whenever a closing parenthesis does not match an opening parenthesis.
DrScheme also flashes quotation mark matches, just like parentheses. Beware, however, that DrScheme cannot distinguish between closing and opening quotation marks. Thus, when you type an opening quotation mark, DrScheme may flash a match to the previous closing quotation mark.
Although whitespace is not significant in Scheme, DrScheme encourages a particular format for Scheme code. When you type Enter or Return, the editor inserts a new line and automatically indents it. To make DrScheme re-indent an existing line, move the flashing caret to the line and hit the [Tab] key. (The caret can be anywhere in the line.) You can re-indent an entire region by selecting the region and typing Tab.
You can edit how Scheme deals with
indentation by choosing Indenting in
the Preference window under the Edit section of the menu, but to make
your code easily readable to others you should stick to a standard indent
style.
2.3.2 Searches
The editor can search for strings of text in the document. There are two types of searches: Pure Searches and Search and Replace
2.3.2.1 Pure Search
A forward search is started by
choosing the Find option in the Edit menu (or pressing C-s). The editor will then prompt you,
with a Find and Replace dialog box, for the string to search for. After
typing it in, the search can be started by Find Button.
2.3.2.2 Search and Replace
The other searches perform search and replace operations. There is a Replace, Replace and Find Again and Replace to End. These will find strings and replace them with ones that you specify. Replace will only replace the text once. Replace and Find Again will replace the text and find the next one. Replace to End will simply replace all of the matches it finds quietly
Warning: Replace to End is extremely dangerous! If you change something there is no easy way to change it back!
To start search and replace
choose Edit>Find to open the Find
window which will prompt you for a string to find and replace. To search and replace text, press the Find
button to find the text and press Replace button to replace the
text. To continue searching and replacing, press Find and then Replace
(Find ® Replace ® Find ®
Replace ®
Find ®
Replace ®
....) or use the Replace and Find Again button (Find ®
Replace and Find Again ® Replace and Find Again ®
Replace and Find Again ® ....) Pressing Replace
to End button will automatically replace all strings you specified.
3 Working with
DrScheme
So
you have started DrScheme ... how do you get anything done? Well you
probably need to write some Scheme forms. The best place to do this is in
an editor window. You could do it at the Scheme prompt in the interaction
window, but if you make a mistake you will have to type in the whole thing
again. An editor will allow you to modify your work.
So now you have typed in a bunch of forms and you want to evaluate them. There are two ways that you can do this. You can copy and paste them from the editor window into the interaction window. This is all right if you don't have too many forms. If, however, you have a large file, the best way to do this is to press the Evaluate button. This will send the entire contents of the editor window to Scheme where it will be evaluated
That is pretty much everything you need to know to get
started with DrScheme.
4 Graphics in
DrScheme
Dr. Scheme supports the same graphics primitives as described in the book, with the following minor differences:
1. You do not need to load the goodie draw.scm, but you still need to create the graphics window before you can draw. This is done by applying the draw-init procedure. This procedure takes zero, one or two arguments:
· If called with no argument (e.g. (draw-init)) you get a 500 x 500 window.
· If called with a single argument (e.g. (draw-init w)) then you get a window whose width and height are both w. So (draw-init 500) is the same as (draw-init).
· If called with two arguments (e.g. (draw-init w h)) then you get a window whose width is w, and whose height is h. Hence (draw-init 500 500) is the same as (draw-init).
2. Once you want to get rid of the window, call (draw-exit).
3. To print the window, use the procedure draw-save (e.g. (draw-save 'file-type "myfile"). The second argument should be the name of the file in which you want to store the picture. The first argument should be one of the following:
|
'xpm |
Should produce a file in xpm format [X-windows].
It works like a charm under Solaris, but not under Windows.
|
|
'bmp |
Should produce a file in bmp (Windows bitmap)
format. This option works the best if you're running Dr. Scheme under some
version of Microsoft Windows. |
To print an xpm
file under Unix, you will need to pipe it through some commands to convert it
to PostScript. This can be done with
the following sequence of commands in an xterm window:
xpmtoppm foo.xpm | pnmdepth 1 | pnmtops >foo.ps
This pipes the foo.xpm file through several
filters so that it end up in PostScript in foo.ps. Now you have the graphic in PostScript format, it is ready to be sent
to the printer using the print command.
print foo.ps
If
you wish, you can first examine the contents of the PostScript file:
ghostview foo.ps