UNB/ CS/ David Bremner/ teaching/ cs2613/ assignments/ CS2613 Assignment 2

What to hand in, and how to hand it in

Marking

Questions

This assignment is based on FICS exercise 31, and the material in Lab 7.

Follow the the rules of the FICS exercices 30, 31. In particular your solution(s) should not use explicit recursion or helper functions. You can (and should) use lambda. For full marks you should not use any builtins other than

Flatten

Write a function flatten that removes one layer of list structure from the input. In particular your function should pass the following tests.

(check-expect (flatten empty) empty)
(check-expect (flatten '(() ())) empty)
(check-expect (flatten '((a) (b))) '(a b))
(check-expect (flatten '(((a 1) (b 1)) ((c 2) (d 2) ))) '((a 1) (b 1) (c 2) (d 2)))

Cross

Write the function cross described in FICS exercice 31. While helper functions are not permitted for this exercise, you can re-use the body of flatten in your cross function if you want. You may find it helpful to debug with a version using flatten as a helper function, and then inline the flatten body before you hand it in.

Your function should pass the following tests.

(check-expect (cross '(a) '(1)) '((a 1)))
(check-expect (cross '(a b c) '(1 2))
              '((a 1) (a 2) (b 1) (b 2) (c 1) (c 2)))

Tests

Make sure that both of your functions are tested adequately. See the rubric for what counts as "adequately".