This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: 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))) 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. (define (find-partners p lst) (cond ((null? lst) '()) ((equal? (cadr p) (cadr (first lst))) (cons (first lst) (find-partners p (butfirst lst)))) (else (find-partners p (butfirst lst)))))...
View Full Document
- Fall '08
- Computer Programming