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

Instructions

  1. The real quiz is individual, so do this one on your own.

  2. Save your answers to a directory labs/L11/ in your cs2613 git repository. Commit and push to https://vcs.cs.unb.ca before 10:20AM. Try to complete the practice quiz in under 1h, to get practice working under time pressure.

  3. This practice quiz is open book. You can use

    1. The local mirror of A Functional Introduction Computer Science (FICS), linked from multiple labs or directly from

      https://www.cs.unb.ca/~bremner/teaching/cs2613/books/FICS/

    2. The local Racket documentation (run raco docs, or the drracket help menu).

    3. Other parts of the course web site

    4. 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

Full marks

For full marks