What to hand in, and how to hand it in
- Make a directory
~/cs2613/assignments/A2
(i.e. in your git repo for this class). All files related to this assigment should be saved in that directory. - Make sure you commit and push all your work using git before 16:30 on Thursday October 10.
Marking
- This assignment will be worth 5% of your final grade.
- For a marking scheme, see racket-assignment
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
define
,check-expect
map
,foldr
lambda
if
,cond
,not
cons
,empty
,list
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".