Computer Science Fundamentals (CS153 2004S)

Laboratory: 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

Short Version

To start DrScheme, click the mouse on the large, round, red icon containing the Greek letter lambda in the middle of the control panel. (If you don't have the lambda, you can open a terminal window and type drscheme.)

The first time you start DrScheme, it will ask you what human language you'd like to use. For this class, you should probably select Interact with DrScheme in English.

DrScheme will also ask you what version of Scheme (which it also calls a language) to use. We explore a lot of Scheme in this course, so we'd like you to use one of the biggest versions, Graphical Scheme. To select that version, you first need to expand the list under PLT, which you can do by clicking on the triangle next to PLT so that it points down. You can then click on Graphical (MrEd, includes MzScheme).

Once you've selected a version of Scheme, click on the Finish button.

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

Short Version

Some people mistakenly choose the wrong version of Scheme to use. These instructions will help you choose the appropriate version.

DrScheme can deal with computer programs written in any of a number of 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 over the triangle to the left of PLT and click on it until it points downward. You should see a few more words indented. Click on Graphical (MrEd, includes MzScheme).

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 log in and choose the appropriate dialect of Scheme before you go on to do any other work in Scheme.

DrScheme's Interactions Pane

Short Version

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

In the interactions pane -- 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 pane 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 pane 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 pane by memorizing it and to each command by carrying out the command. (The expression (sqrt 137641) is a command that saysCompute 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 Pane

Short Version

The upper text area in the DrScheme window, which is called the definitions pane, 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 pane. If you never click on that button, fine -- your program is never executed.

As its name implies, the definitions pane usually contains definitions rather than commands, although either kind of expression can be written in either pane. 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 pane are erased. The idea is that executing the program in the definitions pane 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 pane before clicking on Execute.

Saving to Files

You can save the contents of either pane 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 http://www.drscheme.org.

 

History

Spring 2000 [John Stone]

Monday, 22 January 2001 [Samuel Rebelsky]

Wednesday, 24 January 2001 [Samuel Rebelksy]

Monday, 2 September 2002 [Samuel A. Rebelsky]

Tuesday, 3 September 2002 [Samuel A. Rebelsky]

Wednesday, 4 September 2002 [Samuel A. Rebelsky]

Tuesday, 21 January 2003 [Samuel A. Rebelsky]

 

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

This document was generated by Siteweaver on Fri May 7 09:44:13 2004.
The source to the document was last modified on Thu Jan 22 08:31:04 2004.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS153/2004S/Labs/drscheme.html.

You may wish to validate this document's HTML ; Valid CSS! ; Check with Bobby

Samuel A. Rebelsky, rebelsky@grinnell.edu