Mini Quiz 2
Due by 04/07/2016 at 11:59pm
Instructions
Download mini-quiz02.zip. Inside the archive, you will find a copy of the OK autograder along with the provided tests.
Complete the quiz and submit it before 04/07/2016 at 11:59pm. You must work alone. You may use any course materials, including an interpreter, course videos, slides, and readings. Please do not discuss these specific questions with your classmates, and do not scour the web for answers or post your answers online.
Your submission will be graded automatically for correctness.
Asking Questions: If you believe you need clarification on a question, make a private post on Piazza. Please do not post publicly about the quiz contents. If the staff discovers a problem with the quiz or needs to clarify a question, we will email the class via Piazza. You can also come to office hours to ask questions about the quiz or any other course material, but no answers or hints will be provided in office hours.
Using OK
The ok
program helps you test your code and track your progress.
The first time you run the autograder, you will be asked to log in with your
@berkeley.edu account using your web browser. Please do so. Each time you run
ok, it will back up your work and progress on our servers.
You can run all the unlocking tests with the following command:
python3 ok -u
If you want to see how you did on all tests, you can use the -v
option:
python3 ok -v
If you do not want to send your progress to our server or you have any
problems logging in, add the --local
flag to block all
communication:
python3 ok --local
Submission: You may submit more than once before the deadline; only the final submission will be scored.
When you are ready to submit, run ok
with the
--submit
option:
python3 ok --submit
Readings: You might find the following references useful:
To begin the quiz, use the following ok command:
python3 ok -u
Question 1: WWSP: Scheme Lists
Use OK to test your knowledge with the following "What Would Scheme Print?" questions:
python3 ok -q wwsp-lists -u
scm> (define lst (list () '(1 . 2) '(1 2 . (3))))
_______
scm> (cons (car lst) (car (cdr lst)))
_______
scm> (cons (cdr (car (cdr lst))) (car lst))
_______
scm> (list (car lst) (cdr lst))
_______
scm> (append (car lst) (cdr lst))
_______
scm> (cons (cdr lst) (car lst))
_______
Question 2: Deep Map
Write the function deep-map
, which takes a function fn
and a nested list
s
. A nested list is a list where each element is either a number or a list
(e.g. (1 (2) 3)
where 1
, (2)
, and 3
are the elements). It returns a list
with identical structure to s
, but replacing each non-list element by the
result of applying fn
on it, even for elements within sub-lists. For example:
scm> (define (double x) (* 2 x))
double
scm> (deep-map double '(2 (3 4)))
(4 (6 8))
Assume that the input has no dotted (malformed) lists.
Hint: You can use the functions
map
andlist?
, which checks if a value is a list.
(define (deep-map fn s)
'YOUR-CODE-HERE
nil
)
Use OK to test your code:
python3 ok -q deep-map
After you have unlocked all of the cases, submit your responses with:
python3 ok -v --submit