UNB/ CS/ David Bremner/ teaching/ cs2613/ labs/ Lab 3

Background

Questions from last time

Time
10 Minutes
Activity
Group discussion

In this part of the lab, we will discuss some questions from the On your own part of L02.

Git

Racket

Setup

The first / rest pattern

Time
20 min
Activity
Small groups, programming by example.

Section 2.3.2 of the Racket Guide gives several examples of recursively traversing a list, in particular

(define (my-map f lst)
  (cond
   [(empty? lst) empty]
   [else (cons (f (first lst))
               (my-map f (rest lst)))]))

This function uses a very important pattern, processing the first element of the list with first and recursively processing the remaining elements with rest. In this part of the lab you use this example as a starting point to rewrite the rainbow example from L02 to use explicit recursion (i.e. calling first and rest), rather calling than map.

Unit Tests in Racket

Time
20 min
Activity
Individual work

Unit testing is an important part of programming, and has inspired something called test driven development.

This part is based on an example from RackUnit QuickStart. The Beautiful Racket unit test explainer is a better reference, since we'll skip some of the fancier features of rackunit and move straight to having a test submodule.


Test Coverage

Time
25 min
Activity
Individual work

If you have extra time

Git Bisect

Time
25 minutes
Activity
Small groups

On your own

Time
20 min
Activity
Independent research

See if you can come up with answers to the following questions for next time.