On this page:
Introduction(s)
1 Meet Dr  Racket
2 Finger exercises
6.10

Lab 1: Getting Started

Introduction(s)

You’ll work in labs and on problem sets in pairs, and we’ve randomly assigned your partner for this first lab (and this week’s problem set). Find your partner and introduce yourself. If your partner is not present, let one of your TAs know.

The two of you will work as a team to solve problems. At any time, one of you will be the Head and the other will be the Hands. The Head does the thinking and the Hands does the typing. Hands type only what the Head tells them to, but you’re free to discuss any issues that pop up. We’ll have you switch off during the lab to make sure each of you get practice problem solving, dealing with syntax, and getting finger exercises on the keyboard.

You both should install DrRacket, but only one instance should be use during the lab. At the end you’ll submit the lab as a pair via the UMD CS Submit Server so we can keep an eye on lab attendance.

1 Meet DrRacket

DrRacket is the program you’ll use to design and run your programs. Download, install, and run DrRacket to get started.

Help your partner install it on their machine if you’re done first. Then, pick the first Head and Hands and get continue on only one machine.

Explore DrRacket’s interface. First, find out how to set the current Language to the Beginning Student Language (BSL). We’ll tell you which language to use at the beginning of each lab and problem set.

(Note: if you change the language, you’ll have to hit the <Run> button for it to take effect.)

Next, look through the documentation for the BSL. (Hint: also check the Help menu.) You should get comfortable searching and reading the documentation for anything you need to know about the language and its libraries.

Locate the definitions window and the interactions window

The interactions window lets you quickly make simple calculations. You can type in some expression and hit <Enter> to run it. Test out a few expressions, try to do some arithmetic with big numbers and fractions (or anything else you want to test out).

The definitions window is where you’ll define and develop programs. You execute the code in the definitions window by hitting the <Run> button.

There’s a whole bunch more to explore, but that’s all you need for now. Feel free to try out the Stepper or other features as you program.

If something you type results in red text being printed in the interactions window, the Dr is telling you something unexpected happened. Errors happen a lot, and are a GoodThing™! The Dr is giving you the very best help that it can. Read the message! Figure out what went wrong. Try to fix the problem.

2 Finger exercises

Ex 1: Define a function how-long-at-60-mph that, when given a number that represents distance in miles, will return the time (in hours) it takes to travel that distance when going 60 MPH. Write your function in the definitions window, click Run, then use the interactions window to test your function.

Ex 2: Define a function how-far-at-70-mph that, when given a number representing time in minutes, will return the distance traveled when going 70 MPH, rounding up to whole miles.

Hint: If you don’t know how to perform some particular calculation, search the docs! If you can’t find it in the docs, ask a TA (and show them what you searched for in the docs).

Ex 3: Swap Head and Hands!

When you program, you encounter three kinds of errors:
  • syntax errors, meaning what you wrote is not a BSL expression;

  • run-time errors, that is, you wrote a BSL expression but when you interact with it, DrRacket signals an error (because a function is applied to too many or too few arguments, the wrong kinds of arguments, and so on); and

  • logical errors, which do not manifest themselves as some red text in the interactions area. Instead, you apply a function and it gives you the wrong value back as a result.

Define three variants of the function from Ex 2: how-far-at-70-mph/{syntax,run-time,logical}, each of which demonstrates a different kind of error. Comment out the functions once you’re done.

Ex 4: Add the following expression at the top of your definitions window:

(require 2htdp/image)

The require form lets you use external library definitions in your code. Hit <Run> after adding the require to load the image library.

Find a picture of your favorite animal on the internet (talking to you, Head). Copy and paste it into DrRacket’s definitions window and give it a name (like Chip!).

Draw a frame with a green border around your picture of Chip. As always, the docs can help if you don’t know what functions to use to, for example, make a rectangle or place-images on one another.

Ex 5: Define a function in-a-frame that given a string color (like "red", "blue", "green") places Chip on a frame of that color.