Before the lab
Reading
- Time
- 20 min
- Activity
- Independent research
See if you can come up with answers to the following questions for next time.
The programming languages we will study this term are mainly
dynamically typed. This means that not only the value but also the
type of variables can change at runtime. Why does this make testing
even more important?
What kind of software problems is testing not well suited to find?
Why might mutable state (e.g. instance variables in Java) make
writing unit tests harder?
Questions from last time
- Time
- 10 Minutes
- Activity
- Group discussion
The programming languages we will study this term are all
dynamically typed. This means that not only the value but also the
type of variables can change at runtime. Why does this make testing
even more important?
What kind of software problems is testing not well suited to find?
Why might mutable state (e.g. instance variables in Java) make
writing unit tests harder?
Setup
- make a directory
labs/L04 inside your ~/cs2613 git repository
- All of your work from today should be committed in that directory
(and pushed before you leave).
Substitute in a list
- Time
- 25 minutes
- Activity
- Individual work
- Summary
- Learn about lists and recursion.
Complete FICS Exercise 13.
Note the template for structural recursion.
(define (my-list-fn lst)
(cond
[(empty? lst) ...]
[(cons? lst) ... (first lst) ...
... (my-list-fn (rest lst)) ...]))
Here is a test case based on the linked test
(check-expect
(substitute 3 "three" (list "four" 3 4 "three" 3))
(list "four" "three" 4 "three" "three"))
Uniquifying lists
- Time
- 25 minutes
- Activity
- Individual work
- Summary
- Learn about lists and recursion.
Complete FICS Exercise
15. Although
probably not intended by the original question, use the built-in BSL
function member? to simplify your solution. Otherwise use only the
constructs specified in Exercise 14, and structural recursion.
Here is one test case derived from the linked text.
(check-expect
(unique-right
(list 1 4 2 1 5 4))
(list 2 1 5 4))
Add an element to all lists
- Time
- 25 minutes
- Activity
- Individual work
- Summary
- Learn about lists and recursion.
Recall the template for structural recursion on lists
(define (my-list-fn lst)
(cond
[(empty? lst) ...]
[(cons? lst) ... (first lst) ...
... (my-list-fn (rest lst)) ...])
Use this template to write a function cons-all that adds a given
element to the front of each given sublist. This is related to
FICS Exercises 23-25 (but you only need to write cons-all, not do those exercises).
The following test case illustrates the use of cons-all. You will need to use the language #lang htdp/bsl+ or "Beginning Student with List Abbreviations"
or replace the use of ' in the following.
(check-expect (cons-all 3 '((2 4) () (5)))
'((3 2 4) (3) (3 5)))
Before Next Lab