On this page:
Introduction & Setup
How Labs Operate
Using Dr  Racket
More with Dr  Racket
Programming with Images
Pixar Whomst?
Before You Go...

1 The Basics

home work!

Purpose The first purpose of this lab is to give you some hands-on experience with the BSL programming language and with the DrRacket programming environment for BSL. The second purpose is to pair you up with a partner (see Pair Programming).

Textbook references Preface (DrRacket and the Teaching Languages), Prologue: How To Program, Chapter 2: Functions and Programs (up to but not including 2.5), Chapter 4 (up to but not including 4.5)

Introduction & Setup

Goals: Read and sign the course contract.

Exercise 1 Follow the instructions on this page to set up an account on the handin server. You will be using the handin server to submit all your homeworks for the semester (including the homework that’s due Thursday!).

Exercise 2 Read the course contract and sign it on the handin server.

Exercise 3 Submit the Exam Conflicts assignment on the handin server.

Exercise 4 If you are using your own laptop, download and install DrRacket on your machine. If you are not, count to 10 in your head to keep things fair and balanced.


Goals Partnering.

In this course you will be completing your assignments with a partner. Your partner will be the person sitting next to you in lab. You should also work with them on the lab. You should have one computer for the two of you. One person can man the keyboard, but both partners should be contributing ideas and code. The two of you will get one grade for any given assignment.

Exercise 5 Exchange contact information with your partner: telephone number, latest-greatest social network scheme, whatever-app.

Agree to a first meeting time and meeting place. At that meeting, agree to next meeting time and meeting place.

Exercise 6 Establish your partnership on the handin server. In order to do that you will both need to request the partnership on the handin server. There are instructions here on how to request teammates. Your TAs will approve the team requests as they go through. Once the request is approved you should see your team on the course homepage under "Current teams".

How Labs Operate

Your TA will go over this but you might find it helpful to find it written down. Lab writeups consist of three major parts: sample problems, starter code, and exercises.

Note that for all of these parts, if you are ever stuck or have any questions please raise your hand and a tutor or TA will make their way over to help.

You are free to leave when you have completed the entire lab or the head TA ends lab when time is up.

Using DrRacket

Goals Write a program in DrRacket’s definitions area. Explore the tools and menus of DrRacket. After running check-syntax, find documentation with "right-click" or by pressing F1.

Sample Problem Define a function that accepts a number of minutes and computes how many hours these minutes represent.

(define (minutes->hours num-minutes)
  (/ num-minutes 60))

Sample Problem Define the function how-far which consumes the number of minutes you drive at 55mph and produces how far you get in the given time.

(define SPEED 55)
(define (how-far num-minutes)
 (* (minutes->hours num-minutes) SPEED))

More with DrRacket

Goals: Interact with Dr. Racket’s definitions window, interactions window, and stepper. Create basic expressions and function definitions. Introduce different types of errors.

Exercise 7 Define a function multiple-of-5? that accepts a number and determines if it is a multiple 5. Hint: the function modulo will be helpful to you here.

Exercise 8 Submit your response to the last exercise on the handin server. Note: This is the only exercise you will be submitting in this lab, and it is primarily to make sure you are authenticated with the hand-in server. Either you or your partner can submit, and the submission will be attributed to both of you. So don’t both submit. If you have any trouble submitting this exercise please tell your TA immediately so we can resolve the issue.

Exercise 9 Define a constant GREETING which contains your greeting. Then, use it in a function called greet that takes a name and outputs a full greeting.

Exercise 10 Call these functions in the interactions window. What happens if you call (multiple-of-5? "dog") or (greet #t)?

Exercise 11 Call your functions in the definitions window. Run the stepper on your program. Follow it through to see how it evaluates.

Exercise 12 It has been estimated that fixing the water in Flint, Michigan would cost 55 million dollars. Given someone’s net worth, define a function that will determine what percentage of their net worth it would take to fix the water. Elon Musk’s net worth, for example, is 19.7 billion and Jeff Bezos’ is 140.9 billion.


Goals: Get practice writing conditional functions.

Exercise 13 Define the function absolute which consumes a number and produces the absolute value of that number (do not use abs).

Starter Code: Below is a data definition that defines what a Score can be.

; A Score is a number in the range [0, 100]                     

Exercise 14 Define the function letter-grade. It consumes a Score and produces the corresponding letter grade ("A", "B", "C", "D", or "F"). You may be as wishful as desired in choosing your own grading scale.

Exercise 15 Define a function that given a number of hours worked and an hourly wage computes how much money has been earned. Any hours worked over 40 hours must be paid at 1.5 times the given rate.

Exercise 16 Define the function runtime that given a movie title outputs its runtime in minutes. Ensure the function works on a handful of inputs of your choosing, and for any other inputs throws an error.

Programming with Images

Goals: Get practice programming with images and writing a simple animation.

Starter Code: This line of code is required to program with images.

(require 2htdp/image)

Exercise 17 Use triangle, square, rectangle, above, and overlay/align to draw yourself a house with a roof and door (and circle if you’re feeling bold enough for a door handle).

Exercise 18 Congratulations, you’ve moved up a tax bracket. Define a constant WINDOW and place two of them on your humble home. Note how in using a constant we only have to draw it once and get to use it twice!

Exercise 19 Define a function scene that takes in a natural number and places a circle of that radius at the center of a 50x50 empty-scene. Use modulo to ensure the radius always stays below 20.

Starter Code: These lines of code will turn your scene function into an animation:
(require 2htdp/universe)
(animate scene)

Exercise 20 Launch your animation by pressing run.

Pixar Whomst?

Goals: Use math and conditional programming to make the animation better.

Exercise 21 Use cond (or if if you’re feeling cheeky) to make the circle grow and shrink in a loop instead of grow and suddenly disappear and grow again. Since computing the radius is now a somewhat complex computation, it makes sense to write a separate helper function which only computes the radius that scene calls. Hint: quotient, even?.

Before You Go...

Make sure you can log into the handin server and sign the course contract if you didn’t already do that. If you have any questions regarding the lab or the course please feel free to ask a TA or tutor.