Instructions
The real quiz is individual, so do this one on your own.
Save your answers to a directory
labs/L11/
in yourcs2613
git repository. Commit and push tohttps://vcs.cs.unb.ca
before 10:20AM. Try to complete the practice quiz in under 1h, to get practice working under time pressure.This practice quiz is open book. You can use
The local mirror of A Functional Introduction Computer Science (FICS), linked from multiple labs or directly from
The local Racket documentation (run
raco docs
, or thedrracket
help menu).Other parts of the course web site
Your own notes and work from previous labs and assignments.
Questions
Write a function steamroller
that returns a list of the numbers,
symbols and strings in a given list in order. In particular your
function should pass the following tests.
(check-expect (steamroller empty) empty)
(check-expect (steamroller '(() ())) empty)
(check-expect (steamroller '((a) (b))) '(a b))
(check-expect (steamroller '(((a 1) (b 1)) ((c 2) (d 2) )))
'(a 1 b 1 c 2 d 2))
Notice the behaviour in the last test is to completely flatten the list. Start with the following template for structural recursion on lists
(define (steamroller lst)
(cond
[(empty? lst) ...]
[(cons? lst) ... (first lst) ...
... (steamroller (rest lst)) ...]))
Good solution
To get 7 marks (roughly a “B”), your solution must
- Pass the tests above.
- Be reasonably indented and use reasonable variable names.
- Have full test coverage.
- Use language “htdp/isl+” (Intermediate Student with lambda)
- Only use builtins from the following list
define
,cond
,if
list?
,empty?
,cons?
first
,rest
,empty
,cons
,list
foldr
append
(but only for this part, not the next).
Full marks
For full marks
- Satisfy the conditions above, and
- Do not use the builtin function
append
(you may write your own function that does the same thing if you want). - Add at least two good tests and explain what you are testing.