On this page:
Introduction
Using Dr  Racket
Submitting Homework
Design Exercises
Code Review
6.11.0.4

1 The Basics & Function Design

home work!

Purpose The first purpose of this lab is to practice the systematic design of simple functions in BSL (Beginning Student Language) and the DrRacket development environment. The second purpose is to pair you up with a partner (see Pair Programming). Finally, we would like you to get a first taste of a code review process.

Textbook references Preface (DrRacket and the Teaching Languages), Prologue: How To Program, Chapter 3: Functions and Programs (up to but not including 2.5), Chapter 3: Design (not including 3.4, 3.6, 3.7), Chapter 4 (not including 4.7)

Introduction

5 minutes

Goals Who we (the teaching assistants and tutors) are? Partnering.

Exercise 1 Find a partner to work with in the lab and on homework assignments, for example, the person next to you. The two of you will get one grade for labs and homework.

Exchange contact information with your partner: telephone number, latest-greatest social network scheme, what-ever-app.

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

Using DrRacket

10 minutes

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;" find documentation with F1.

Sample Problem Define a function that accepts a number of minutes and computes how many whole 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))

Submitting Homework

10 minutes

See The Handin Server for instructions on how to deal with the handin server.

Exercise 2 Upload one of the above functions. Check to make sure you submitted correctly.

Design Exercises

35-40 minutes

Solve the following exercises. Proceed in order; if you get stuck, skip the exercise and move to the next one. Don’t forget to revisit an exercise if you skipped it.

Exercise 3 Design the function describe. It accepts an instance of worm:
(define-struct worm (its-name head body))
(define-struct head (mouth radius))
; An Worm is (make-worm String Head PositiveNumber).
; A  Head is (make-head Mouth PositiveNumber).
; A  Mouth is one of:
;  "open"
;  "closed"
The function forms a sentence of the shape

"___'s mouth looks ___."

where the first blank space is replaced by the name of the worm and the second one by either "round" for an open mouth and "like a line" fo a closed one.

Exercise 4 Design the function letter-grade. It consumes a exam score (number) between 0 and 100 and produces the corresponding letter grade ("A", "B", "C", "D", or "F"). You may choose your own grading scale.

Exercise 5 Design the function sale. It accepts a wish in the form of a String and, if it recognizes the string, it returns an image of this object; otherwise it produces an image made from "sorry". You may decide which wishes to accept. You can use images from the web or build the images yourself using circles, squares, and other shapes that you can draw in DrRacket.

Code Review

25-30 minutes

The Teaching Assistants will pick two pairs who will explain a solution to their lab mates following the design recipe steps.