Interface Essentials

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.

[drscheme-Z-G-1.gif]

The top editing panel, called the definitions window, is for defining Scheme programs. The above figure shows a program that defines the function square.

The bottom panel, called the interactions window, is for evaluating Scheme expressions interactively. The Language line in the interactions window indicates which primitives are available in the definitions and interactions windows. In the above figure, the language is Beginning Student, which is the default language.

Clicking the Run button evaluates the program in the definitions window, making the program's definitions available in the interactions window. Given the definition of square as in the figure above, typing (square 2) in the interactions window produces the result 4.

The status line at the bottom of DrScheme's window 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.

2.1  Buttons

The left end of the row of buttons in DrScheme contains a miniature button with the current file's name. Clicking the button opens a menu that shows the file's full pathname. Selecting one of the menu entries produces an open-file dialog starting in the corresponding directory.

Below the filename button is a (define ...) button for a popup menu of names that are defined in the definitions window. Selecting an item from the menu moves the blinking caret to the corresponding definition.

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.

The Step button -- which appears only for the How to Design Programs teaching languages ``Beginning Student'' through ``Intermediate Student with Lambda'' -- starts the Stepper, 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. For example, a step might replace (+ 1 2) with 3. These are the same rules used by DrScheme to evaluate a program. Clicking Step opens a new window that contains the program from the definitions window, plus several new buttons: these buttons allow navigation of the evaluation as a series of steps.

The Debug button -- which does not appear for the How to Design Programs teaching languages -- starts a more conventional stepping debugger. It runs the program in the definitions window like the Run button, but also opens a debugging panel with Pause, Continue, and Step buttons. A newly started program is paused the program's first possible pause point, and the current pause location is shown with a green arrow. Click the Continue button to continue running the program, click Step to run until the next possible pause point, and right-click on an expression's open or close parenthesis to set or remove an explicit pause. (Valid pause points are highlighted with a pink dot as you mouse over the program text.) When the program is paused, move the mouse over a variable to display its value in the debugging panel to the right of the buttons. When pausing at an expression's result, the result is shown to the left of the debugging panel's buttons, and the result can be changed by right-clicking the pause point. Click the Stop button to stop debugging so that the program in the definitions window can be edited. Debugging also stops when all expressions in the definition window have been evaluated.

Clicking the Check Syntax button annotates the program text in the definitions window. It add these annotations:

The Run button evaluates the program in the definitions window and resets the interactions window.

The Break button interrupts an evaluation, or beeps if DrScheme is not evaluating anything. For example, after clicking Run 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 kill the evaluation immediately.

2.2  The Editor

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.

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

DrScheme also rewrites parenthesis as you type them, in order to make them match better. If you type a closing parenthesis ``)'', a closing square bracket ``['', or a closing curley brace ``}'', and DrScheme can match it back to some earlier opening parenthesis, bracket, or brace, DrScheme will change what you type to match. DrScheme also rewrites open square brackets, usually to an open parenthesis. There are some exceptions, where opening square brackets are not automatically changed to parentheses:

The upshot of DrScheme's trickery: always use the (presumably unshifted) square brackets on your keyboard to type parenthesis. For example, when typing this:

(define (length l)
  (cond
   [(empty? l) 0]
   [else (+ 1 (length (rest l)))]))

If you always type ``['' and ``]'' where any of the square brackets or parentheses appear, DrScheme will change the square brackets to match the code above.

Of course, these features can be disabled in the preferences dialog (see section 3.2). Also, in case DrScheme is only being too clever occasionally, holding down the control key while typing a parenthesis prevents DrScheme from changing it.

2.3  The Interactions Window

The interactions window lets you type an expression after the > prompt for immediate evaluation. You cannot modify any text before the last > prompt. To enter an expression, the blinking caret must appear after the last prompt, and also after the space following the prompt.

When you type a complete expression and hit Enter or Return, DrScheme evaluates the expression and prints the result. After printing the result, DrScheme creates a new prompt for another expression. Some expressions return a special ``void'' value; DrScheme never prints void, but instead produces a new prompt immediately.

If the expression following the current prompt is incomplete, then DrScheme will not try to evaluate it. In that case, hitting Enter or Return produces a new, auto-indented line. You can force DrScheme to evaluate the expression by typing Alt-Return or Command-Return (depending on your platform).

To copy the previous expression to the current prompt, type ESC-p (i.e., type Escape and then type p). Type ESC-p multiple times to cycle back through old expressions. Type ESC-n to cycle forward through old expressions.

Clicking the Run button evaluates the program in the definitions window and makes the program's definitions available in the interactions window. Clicking Run also resets the interactions window, erasing all old interactions and removing old definitions from the interaction environment. Although Run erases old > prompts, ESC-p and ESC-n can still retrieve old expressions.

2.4  Tabbed Editing

DrScheme's allows you to edit multiple files in a single window, via tabs. The File|New Tab creates a new tab to show a new file. Each tab has its own interactions window.

In the General sub-pane of the Editing pane in the preferences window, a checkbox labelled Open files in separate tabs causes DrScheme to open files in new tabs in the frontmost window, rather than opening a new window for the file.

The key bindings Control-Pageup and Control-Pagedown move between tabs. Under Mac OS X, Command-Shift-Left and Command-Shift-Right also move between tabs.

2.5  Errors

Whenever DrScheme encounters an error while evaluating an expression, it prints an error message in the interactions window and highlights the expression that triggered the error. The highlighted expression might be in the definitions window, or it might be after an old prompt in the interactions window.

For certain kinds of errors, DrScheme turns a portion of the error message into a hyperlink. Click the hyperlink to get help regarding a function or keyword related to the error.

2.6  Languages

DrScheme supports multiple dialects of Scheme. The name of the current evaluation language always appears in in the top of the interactions window. To choose a different language, select the Language|Choose Language... menu item. After changing the language, click Run to reset the language in the interactions window.

Five of DrScheme's languages are specifically designed for teaching:

The teaching languages different from conventional Scheme in a number of ways, described below.

DrScheme also supports several languages for experienced programmers:

The Language|Choose Language... dialog contains a Show Details button for configuring certain details of the language specification. Whenever the selected options do not match the default language specification, a Custom indicator appears next to the language-selection control at the top of the dialog.

The teaching languages differ from conventional Scheme in a number of ways:

The teaching languages also deviate from traditional Scheme in printing values. Different printing formats can be selected for any language through the detail section of language-selection dialog.

2.7  Executables

DrScheme's Create Executable... menu item lets you create an executable for your program that you can start without first starting DrScheme. To create an executable, first save your program to a file and set the language and teachpacks. Click Run, just to make sure that the program is working as you expect. The executable you create will not have a read-eval-print-loop, so be sure to have an expression that starts your program running in the definitions window before creating the executable.

Once you are satisfied with your program, choose the Create Executable... menu item from the Scheme menu. You will be asked to choose an executable file name or an archive file name. In the latter case, unpack the generated archive (on this machine or another one) to access the executable. In either case, you will be able to start the executable in the same way that you start any other program on your computer.

The result of Create Executable... is either a launcher executable, a stand-alone executable, or a distribution archive, and it uses either a MzScheme (textual) or MrEd (graphical) engine. For programs implemented with certain languages, Create Executable... will prompt you to choose the executable type and engine, while other languages support only one type or engine.

Each type has advantages and disadvantages:

TIP: Disable debugging in the language dialog before creating your executable. With debugging enabled, you will see a stack trace with error messages, but your program will run more slowly. To disable debugging, open the language dialog, click the Show Details button, and select No debugging or profiling, if it is available.

2.8  Printed Results

This section describes the different formats that DrScheme uses for printing results in the interactions window. Each of the different settings here also apply to the print primitive. That is, printing in the interactions window is identical to output produced by the print primitive.

2.8.1  Constructor-style Output

DrScheme's constructor-style output treats cons, vector, and similar primitives as value constructors, rather than functions. It also treats list as shorthand for multiple cons's ending with the empty list. Constructor-style printing is valuable for beginning computer science students, because output values look the same as input values.

Results printed in DrScheme's interactions window using constructor-style printing look different than results printed in traditional Scheme implementations, which use write to print results. The table in Figure 1 shows the differences between values printed in constructor style and values printed with write.

[drscheme-Z-G-2.gif]
Figure 1:  Comparison of constructor-style output to write

2.8.2  Quasiquote-style Output

Constructor-style output is inconvenient for printing S-expression results that represent programs. For example, the value '(lambda (x) (lambda (y) (+ x y))) prints as

(list 'lambda (list 'x) (list 'lambda (list 'y) (list '+ 'x 'y)))
with constructor-style printing.

DrScheme's quasiquote-style output combines the input-output invariance of constructor-style printing with the S-expression readability of write. It uses quasiquote to print lists, and uses unquote to escape back to constructor style printing for non-lists and non-symbols.

With quasiquote-style printing, the above example prints as:

`(lambda (x) (lambda (y) (+ x y)))

This example:

(list 'lambda (list 'x) (box '(lambda (y) (+ x y))))
in quasiquote-style printing prints as:
`(lambda (x) ,(box `(lambda (y) (+ x y))))

2.9  Input and Output

Many Scheme programs avoid explicit input and output operations, obtaining input via direct function calls in the interactions window, and producing output by returning values. Other Scheme programs explicitly print output for the user during evaluation using write or display, or explicitly request input from the user using read or read-char.

Explicit input and output appear in the interactions window, but within special boxes that separate explicit I/O from normal expressions and results. For example, evaluating

[drscheme-Z-G-3.gif]

in the interactions window produces a special box for entering input:

[drscheme-Z-G-4.gif]

(The underscore indicates the location of the blinking caret.) Type a number into the box and hit Enter, and that number becomes the result of the (read) expression. Once text is submitted for an input box, it is moved outside the input box, and when DrScheme shows a new prompt, it hides the interaction box. Thus, if you type 5 in the above input box and hit Return, the result appears as follows:

[drscheme-Z-G-5.gif]

In this case, the first 5 is the input, and the second 5 is the result of the (read) expression. The second 5 is colored blue, as usual for a result printed by DrScheme.

Output goes into the interaction window directly. If you run the program

(define v (read))
(display v)
v

and provide the input S-expression (1 2), the interactions window ultimately appears as follows:

[drscheme-Z-G-6.gif]

In this example, display produces output immediately beneath the input you typed, and the final result is printed last. The displayed output is drawn in purple. (The above example assumes constructor-style printing. With traditional value printing, the final line outside the box would be (1 2).)

Entering the same program line-by-line in the interactions window produces a different-looking result:

[drscheme-Z-G-7.gif]

Depending on the input operation, you may enter more text into an input box than is consumed. In that case, the leftover text remains in the input stream for later reads. For example, in the following interaction, two values are provided in response to the first (read), so the second value is returned immediately for the second (read):

[drscheme-Z-G-8.gif]

The following example illustrates that submitting input with Return inserts a newline character into the input stream:

[drscheme-Z-G-9.gif]

2.10  XML

DrScheme has special support for XML concrete syntax. The Special menu's Insert XML Box menu inserts an embedded editor into your program. In that embedded editor, you type XML's concrete syntax. When a program containing an XML box is evaluated, the XML box is translated into an x-expression (or xexpr). Xexprs are s-expression representation for XML expressions. Each xexpr is a list whose first element is a symbol naming the tag, second element is an association list representing attributes and remaining elements are the nested XML expressions.

XML boxes have two modes for handling whitespace. In one mode, all whitespace is left intact in the resulting xexpr. In the other mode, any tag that only contains nested XML expressions and whitespace has the whitespace removed. You can toggle between these modes by right-clicking or control-clicking (Mac OS X) on the top portion of the XML box.

In addition to containing XML text, XML boxes can also contain Scheme boxes. Scheme boxes contain Scheme expressions. These expressions are evaluated and their contents are placed into the containing XML box's xexpr. There are two varieties of Scheme box: the standard Scheme box and the splicing Scheme box. The standard Scheme box inserts its value into the containing xexpr. The contents of the splice box must evaluate to a list and the elements of the list are ``flattened'' into the containing xexpr. Right-clicking or control-clicking (Mac OS X) on the top of a Scheme box opens a menu to toggle the box between a Scheme box and a Scheme splice box.

2.11  Test Cases

DrScheme also includes support for creating test cases as part of the program text. This support is designed as an aid for students building tests as part of the How to Design Programs design recipes.

Test cases in DrScheme are written in special boxes. To create one, choose Insert Test Case from the Scheme menu in the DrScheme window. The test cases consists of three editable areas. From the top, the first is a comment that names the test case. The second is an expression to test. The third is the expected result. Below the expected result is a light-blue box that will contain the actual result of the expression to be tested. Clicking on the triangle in the top-right hides the expression to test and the expected and actual results.

To run test cases, simply click Run. The top-right corner of the test case will change to either be a check box or a red X, indicating success or failure of the test case.

To disable all of the test cases in the definitions window, choose the Disable All Test Cases menu item in the Scheme menu.


1 More precisely, Pretty Big is MrEd extended with the following MzLib libraries (see PLT MzLib: Libraries Manual): etc.ss, file.ss, list.ss, class.ss, unit.ss, unitsig.ss, include.ss, defmacro.ss, pretty.ss, string.ss, thread.ss, math.ss, match.ss, and shared.ss.