This guide explains the most important things you need to know to get started working with DrRacket on CS1120 problem sets.
All the software we use is freely available, open source software, and should work on at least Mac OS X, Microsoft Windows (any recent version), and Linux.
Even if you are using your own laptop, though, you are highly encouraged to work in the designated CS1120 lab space so you will benefit from the staffed lab hours as well as the presence of your fellow classmates. The schedule for office and lab hours is posted on the course site. If you do not have access to a laptop, DrRacket is already installed on the public ITC machines (there are not many of these left, but a few in Alderman library and other places on grounds) and in the Olsson Hall 001 lab machines.
The integrated programming environment (IDE) used in this class for Scheme is DrRacket (previously known as “DrScheme”). DrRacket is installed in the labs and is available for free download from http://racket-lang.org/download/. Many platforms are supported including Windows, Mac OS X, and Linux.
After you have successfully installed DrRacket, run it by clicking on the logo that looks like a lambda (λ) symbol colored in red and blue. (Where the logo will be depends on your platform and how you installed DrRacket. For Windows, it can be found by clicking on the Start menu and All Programs and Racket. I recommend pinning the logo to the taskbar by dragging it there.)
You can also launch DrRacket by double-clicking on a Scheme code file (with a .rkt, .ss, or .scm extension).
When DrRacket starts, you will see a window like this:
DrRacket isn’t specific to Scheme. It supports several languages. The first time you run DrRacket, you need to choose a programming language. Enter Ctrl-L to bring up the Choose Language dialog box. Select the language Pretty Big,a variant of Scheme, from the Legacy Languages list and click OK:
After choosing the language, you can edit and evaluate expressions in DrRacket.
The top half is the Definitions window, the bottom half is the Interactions window. You can make one of the windows disappear (and the other one take over the whole screen) by using Show | Hide Definitions or Show | Hide Interactions under the View menu.
You should use the Definitions window to edit all the code you will turn in, and use the Interactions window to try evaluating small expressions and to test your code. You can evaluate expressions directly in the Interactions window to just try them out. For instance, try typing (+ 1000 120) in the Interactions window, hit return. DrRacket will display:
> (+ 1000 120)
You can evaluate any Scheme expression you want in the Interactions window, including definitions. However, whenever you click Run all the definitions you entered in the Interactions window are lost.
The Run button loads the contents of the Definitions window into the Interactions window. Be careful to remember that clicking Run does not also save your definitions to the disk. To save your definitions, you must click the Save button which will appear after you make a change in the Definitions window.
Remember to save your code often. It is also a good idea to save copies under different names so you can compare to earlier versions if something breaks when you make a change.
Use esc-p in the Interactions window to cycle through previous commands. This can save lots of typing.
If you are working on the public ITC machines, you will need to work out of your home directory (usually the J: drive on ITC machines). To open home directory, click on the house icon on your desktop and enter in your user id and password. To create a cs1120 sub-directory in your home directory, right click in your home directory and select New Folder. Rename the New Folder cs1120. Then, open the cs1120 folder, and then create another new folder for the current problem set (for example ps0). We recommend you create a new folder for each problem set to avoid confusion with multiple files.
If you are working on your own machine, it is highly advisable to set up a cs1120 directory that will be backed up and accessible to you over the network for your cs1120 work. If you are not already using some other service for this, we recommend installing DropBox (which is free for up to 2GB, which should be plenty for this class).
In both the Definitions and Interactions windows, you can type and edit text. The editor is similar to WordPad or NotePad, but is designed especially for editing Scheme code.
Scheme interprets everyting to the right of a semicolon (;) as a comment. You should always start your file with comment lines that include your name and UVa computing id (e.g., dee2b).
You'll notice when you type a right parenthesis ()), DrRacket will highlight the Scheme expression that it closes (that is, between it and the the matching left parenthesis). This provides a useful clue to notice if you have forgotten or misplaced a parenthesis.
In the Definitions window, when you press return, the editor will go to a new line and automatically indent it according to the structure of your Scheme expression.
You can use Ctrl-f in the editor to search for a string. To quickly find a definition, click on the (define …) button (at the top left) to reveal a list of all names that are defined in the Definitions window. Click on the name you want to jump directly to that definition.
When something goes wrong in evaluating an expression, DrRacket will produce an error message like this:
The expression that was being evaluated will be highlighted in pink. If you click on the leftmost red circle with white inscribed cross at the left of the message, DrRacket will pop up a window that shows you what was being evaluated when the problem occured.
To print the code in your Definitions window, go to File and select Print Definitions. To print your output in the Interactions window, go to File and select Print Interactions.
Please make sure that what you turn in for a problem set clearly marks the questions you are answering. You should not include provided code that you did not change in what you turn in.
An online manual for DrRacket is available.
Credits: This guide was originally developed by Katie Winstanley and David Evans for CS200 Spring 2003, and has been revised by Westley Weimer (Spring 2009) and Paul Reynolds (Spring 2011).