Question 1 (6 points):
What will Scheme print in response to the following expressions?
If an expression produces an error message, you may just write
"error"; you don't have to provide the exact text of the message.
Also, draw a box and pointer diagram for the value produced by
each expression.
(map caddr '((2 3 5) (7 11 13) (17 19)))
(list (cons 2 (cons 3 5)))
(append (list '(2) '(3)) (cons '(4) '(5)))
This
preview
has intentionally blurred sections.
Sign up to view the full version.
Question 2 (7 points)
Suppose you are in a team working on a social networking program.
You are given the constructor of a "person" data structure.
(define (make-person first-name last-name favorite-sport
favorite-movie)
(list (list first-name last-name)
favorite-sport
(cons 'movie-favorite-movie)))
a) Write the selectors:
(define (first-name person))
(define (last-name person))
(define (favorite-movie person))
(define (favorite-sport person))
b) Your partner wrote a procedure find-partners that takes a
person p and a list of persons lst as arguments, and returns the
persons in the list that have the same favorite sport as p. Fix
all the data abstraction violations in his code.

This is the end of the preview.
Sign up
to
access the rest of the document.
- Fall '08
- Harvey
- Computer Programming, Vowel, Emoticon, Timmy, Draw-A-Person Test, Pig Latin
-
Click to edit the document details