Fundamentals of CS I (CS151 2001S)

The DrScheme programming environment

Note: Each member of your group should do this lab working within his or her own account.

Many of the fundamental ideas of computer science are best learned by reading, writing, and executing small computer programs that illustrate them. One of our most important tools, therefore, is a computer program designed specifically to make it easier to read, write, and execute other computer programs. In this class, we will often use a programming environment named DrScheme.

Starting DrScheme

To start DrScheme, click the mouse on the large, round, red icon containing the Greek letter lambda in the middle of the control panel. Shortly, DrScheme will start up and appear as a new window, with two white rectangular text areas against a dark gray background.

At the top of the window, just below the frame, is a menu bar, providing ways of activating various operations that DrScheme can perform. Eventually we'll explore a number of these, but for the moment let's just look at one that you're certain to need: the operation of shutting itself down.

Move the mouse pointer onto the word File at the left end of the menu bar and click the left mouse button. A small menu appears.

Move the mouse pointer onto the word Quit at the bottom of this menu and click the left mouse button. DrScheme responds by popping up a confirmation box of its own, the purpose of which is to make sure that you don't shut down DrScheme by mistake.

Move the mouse pointer onto the word Quit in the confirmation box and click the left mouse button. Both the confirmation box and the main DrScheme window disappear.

DrScheme language options

DrScheme can deal with computer programs written in any of four dialects of the Scheme programming language. When you start it up for the first time, it expects you to use Beginning Student Scheme, which is a kind of training-wheels dialect that enables DrScheme to catch and diagnose some common mistakes of novice programmers.

Since we want to use consistent materials and language throughout the semester, we're going to proceed directly to ``Full Scheme,'' which is more nearly standard. To inform DrScheme of this decision, we'll need another of the operations accessed through the menu bar. If you exited from DrScheme, restart it now. When the window appears, move the mouse pointer onto the word Language on the menu bar and click the left mouse button to bring up the Language menu. Move the mouse pointer onto the phrase Choose Language and click the left mouse button again to select that operation. Another window appears.

Move the mouse pointer onto the phrase Beginning Student and press and hold the left mouse button. A menu appears, but it is visible only as long as you hold the left mouse button down. Drag the mouse pointer onto the phrase Full Scheme and then release the left mouse button. The window changes to show the ``Full Scheme'' language options.

Move the mouse pointer onto the word OK and click the left mouse button. The extra window disappears, leaving the DrScheme window. Next, move the mouse pointer onto the word Execute (next to a green arrow, just below the menu bar) and press the left mouse button. DrScheme now expects programs in the dialect it calls ``Graphical Full Scheme.''

DrScheme retains the information that you prefer to use full Scheme, so that when you log in again tomorrow and start DrScheme again, it will automatically expect programs in that dialect. You won't need to use the Choose Language operation again unless you decide that you'd like to experiment with Beginning Student Scheme or some other dialect.

Make sure that all members of your group login in and choose the appropriate dialect of Scheme before you go on to do any other work in Scheme.

DrScheme's Interactions Window

Now you're ready to look at the parts of DrScheme.

In the interactions window -- the lower of the two large text areas -- DrScheme displays a one-line greeting, a reminder of which dialect of Scheme it expects to see, and a prompt (in this case, a greater-than sign), indicating that DrScheme is ready to deal with any command that you type in.

To enter a Scheme program, move the mouse pointer to the right of the prompt, click the left mouse button, and type in the program. (If you prefer, you can select the program from another window by moving the mouse pointer to the beginning of the program, pressing and holding the left mouse button, dragging the mouse pointer to the end of the program, and releasing the left mouse button. The background color against which the text that you have selected changes during this process, so that you can see the boundaries of the selection clearly. You can then paste the selected text into the interactions window by moving the mouse pointer to the right of the prompt and clicking the middle mouse button.)

To get DrScheme to execute your program, press the Enter key after the right parenthesis. At this point, DrScheme examines your program, translates it into a sequence of instructions to the computer's central processor (the electronic circuit that directs the movement and transformation of data inside the computer), executes it, and prints out the result of its computation. Because this particular program is extremely simple, the result is printed immediately.

You may notice that DrScheme prints out another prompt after executing your program. This is because DrScheme cannot be sure that it has seen all the steps in the program. A program written in Scheme has a particularly simple structure: it is a sequence of definitions and commands -- any number of them, in any order. DrScheme reacts to each definition that you type into the interactions window by memorizing it and to each command by carrying out the command. (The expression (sqrt 137641) is a command -- ``Compute the square root of 137641!'') Because a program might contain several commands rather than just one, DrScheme has to be prepared to receive another after carrying out the first.

DrScheme's definitions window

The upper text area in the DrScheme window, which is called the definitions window, is used when you want to prepare a program ``off-line,'' that is, without immediately executing each step. Instead of processing what you type line by line, DrScheme waits for you to click on the button labelled Execute (the second button from the right, in the row just below the menu bar) before starting to execute the program in the definitions window. If you never click on that button, fine -- your program is never executed.

As its name implies, the definitions window usually contains definitions rather than commands, although either kind of expression can be written in either window. The difference is simply that we generally want an immediate response to a command, whereas definitions are usually processed in bulk.

Warning: When you click on the Execute button, the contents of the interactions window are erased. The idea is that executing the program in the definitions window may invalidate the results of previous interactions. Erasing the results that may now be inconsistent with the new definitions ensures that all visible interactions use the same vocabulary. This is actually a helpful feature of DrScheme, but it can take you by surprise the first time you see it happen. Just make sure that you have everything you need from the interactions window before clicking on Execute.

Saving Windows to Files

You can save the contents of either window in a file at any time by selecting Save Definitions As Text or Save Interactions As Text from the File menu. DrScheme pops up a window in which you can specify the name of the file:

Edit the contents of the white text field near the bottom of the pop-up window, adding a slash and the name of the file. Click on the OK button to dismiss the pop-up window.

DrScheme Outside the MathLAN

While we would prefer that you do your work for this class in the MathLAN so that you have a support network available, it is possible to run DrScheme on almost any computer, including Macs and PCs running Microsoft Windows. You can download a copy from



Spring 2000 [John Stone]

Monday, 22 January 2001 [Samuel Rebelsky]

Wednesday, 24 January 2001 [Samuel Rebelksy]


Disclaimer: I usually create these pages on the fly. This means that they are rarely proofread and may contain bad grammar and incorrect details. It also means that I may update them regularly (see the history for more details). Feel free to contact me with any suggestions for changes.

This page was generated by Siteweaver on Thu May 3 23:07:43 2001.
This page may be found at
You may validate this page's HTML.
The source was last modified Wed Jan 24 23:32:53 2001.