Due: Tuesday, Sept 28, end of your lab session
Lab1
In this lab you will familiarize yourself with the basics of DrRacket.
Get ready...
Step 1 (Requesting your CS account):
Step 2 (Subscribing to the class mailing list):
Step 3 (Familiarizing yourself with class tools):
Set...
- Locate and run the DrRacket application on the dock
or in your applications folder on your computer (under folder Racket5.0)

- We will define our programs in the upper region (i.e. definitions window) and evaluate Racket expressions in the lower panel (i.e. interactions window)
Selecting a language
- Before we begin, we must first select the language to work with: from the "Languages ->Choose Language" menu item, choose "Beginning Student" from the How to design programs section. We then click the "Run" button and the selected language will show up in the status bar at the bottom of the interactions window.
Adding a teachpack
- For lab1, we will use the "image.ss" teachpack. From the "Language -> Add teachpack" menu select the "image.ss" teachpack, click OK and then the "Run" button. At this time, the status bar below should display "Beginning Student custom".
Go!
1.
Move the cursor to the lower interactions panel and at the command prompt > try:
- Type in "hi" and press Enter. Note how the read-evaluate-print (REPL) loop produces a response: "hi". DrRacket reads in this string literal we typed in and evaluates it to itself. Type in 'hi and press Enter. The response for evaluating the symbol 'hi is 'hi. What happens if you type in hi?
- Type in 5 and press Enter. The number 5 is also evaluated to value 5.
- Type in (+ 1 2) and press Enter. This time, DrRacket evalues this expression to value 3. Try evaluating (+ 1 2 3). Note that the form of this numerical expression is (operator operand_1... operand_n). +,-,/,* are primitive arithmetic operators. Each operand can be complex, try evaluating (+ (* 2 3) (- 8 2)). Try typing in (+ and then press Enter and type the subexpressions (* 2 3) and (- 8 2) and the final ) on subsequent separate lines. Notice the indentation DrRacket provides, placing the two subexpression at the same indentation level to indicate they are both operands for the addition operator.
- What happens if you type (+ 2)? What happens if you type (3 + 3)? What happens if you type (+ 3 3?
- Type in (abs -5). abs is a primitive operation that computes the absolute value of a number. What happens if you type in (Abs -5)? Search for the details of the abs function in the help desk.
Move your cursor to the definitions window and type in the correct expressions from steps 1, 2, 3 and 5 above on separate lines. Press the "Run" button at the top of the definitions window. Note that the same evaluation results you got before are output in the interactions window. This is our first very simple program consisting of a set of simple evaluations.
To follow these evaluations step by step we can make use of DrRacket's step tool. Press the "Step" button. Notice how you can move forward and backward in the evaluation process step by step. The left-hand side highlights in green the subexpression evaluated in the current step, while the right-hand side highlights in purple the result of this evaluation.
Especially when writing larger programs, it is vital to include explanatory comments alongside your code. Lines starting with a semicolon are considered comments in DrScheme and are ignored in the evaluation process. Precede any of the lines in your definition windows with a semicolon and note what happens when you click "Run".
Write one comment for each of the faulty expressions from 1-5 above, noting the error you observed and your thoughts on its interpretation.
This is a good time to save your work!
Saving your work
Save your work in your home directory in a folder (e.g. named "lab1"). This is your submission directory, where all the files associated with your lab will be located. (e.g. /home/youraccountusername/lab1). Use the "File -> Save definitions" menu to save your work in the definitions window into your submission directory. This will create a .rkt file. Exit the DrRacket application and start it once more. Open the file you have saved earlier using the "File -> Open" menu item. You can also keep track of your interactions with DrRacket by saving your interactions through the "File -> Save interactions" option (but you will not need to submit this file).
2.
The image.ss teachpack provides primitives for operating with images. Details on working with this teachpack are available at http://docs.racket-lang.org/teachpack/image.html or through the DrRacket's help desk. Please open this page and consult it as you go along the following warm up exercises. As before, make sure at the end of these exercises you have them and your comments in the definitions window.
- Type in (circle 10 'solid 'darkblue). DrRacket understands HTML colors which can look up here.
- Type in (define dbcircle (circle 10 'solid 'darkblue)). Notice that there is no response, except a new cursor. Type in dbcircle. Through this definition you have associated the identifier dbcircle with the value of our blue circle image. Type in (define mcircle (circle 20 'solid 'magenta)) and then mcircle.
- Type in (pinhole-x dbcircle) and then (pinhole-y dbcircle). Notice the response. Each image has a pinhole which can be used to control how images are displayed. By default, the pinhole of a circle is located at the center of the circle. So for our circle of radius 10, this will be at location (10, 10). The top left corner of the display area is considered to be of coordinates (0,0). You can read more about pinholes in the documentation.
- Type in (overlay mcircle dbcircle) and then (overlay dbcircle mcircle). What is the difference between the images produces by each expression? Why do you think this happens? Please write your response as a comment in the definitions window.
- Type in (overlay/xy mcircle 30 0 dbcircle). Notice how the magenta and darkblue circles are aligned. Our mcircle has a radius of 20, while dbcircle has a radius of 10. Overlay/xy moves the pinhole of the first image by 30 horizontally and by 0 vertically. This places the pinhole outside of mcircle, at distance 10 from the circle boundary along the horizontal direction. The second image (dbcircle) is overlayed onto this pinhole and since the radius of dbcircle is 10, the circles become tangent.
Please make sure your definitions window contains these exercises and your comments and that you have saved your work. You should start working on part 3 of the lab, but are not required to finish by the end of the lab session. Please turn in your solutions for all lab parts (including whatever you have completed of part 3) at the end of the lab session. You will be graded on parts 1 and 2 of the lab, while homework1 will include part 3 of the lab.
3.
Using the functions in the image.ss teachpack, create the following image of a traffic light (Assume the radius of all circles is 10).

Submitting your work
For this lab, you will only need to submit one .rkt file with the content your definitions window. Follow the steps in the "Saving your work" section to create this file and make sure you have saved the latest version of your work in your submission directory.
- Open a terminal window and copy your submission folder into your CS account. You can use any of the hostnames listed at the top of the MacLab start page (http://maclab.cs.uchicago.edu/). For example to copy your submission directory to your home directory in your CS account using host ursa:
scp -r yoursubmissiondirname yourCSaccountname@ursa.cs.uchicago.edu:~/
- SSH into your CS account, e.g.:
ssh yourCSaccountname@ursa.cs.uchicago.edu
- We will use the hwsubmit UNIX command to submit your lab work. Check that your submit directory contains the files you would like to submit using e.g.
ls -l yoursubmissiondirname
Submit your homework:
hwsubmit cmsc10500lab yoursubmissiondirname
Please remember that your work is due at the end of the lab session. Make sure you have submitted your work before you leave the lab.