CS61A_sp92_mt2 - CS61A: Midterm #2-Spring 1992 CS61A,...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CS61A, Spring 1992 Midterm #2 Question 1 (4 points): What will Scheme print in response to the following expressions? Also, draw a ``box and pointer'' diagram for the result of each expression: (cons (cdr '(x)) 3) (list 2 '(3 4)) ((lambda (s) (cons (car s) (cddr s))) '(w x y z)) (cons (list 2 3) '(a)) Question 2 (5 points): Write a function uniq (named after a Unix utility program that does more or less the same thing) that takes a list as its argument. It should return a list that has the same elements, except that if an element is repeated several times in a row, it only appears once in the result list: > (uniq '(a x b b b c c c c x d)) (a x b c x d) > (uniq '(3 3 3 3 3 3 3 3 4 4 4 7 hello hello hello)) (3 4 7 hello) Question 3 (5 points): Write a function add-numbers that takes as its argument an arbitrary hierarchical list (that is, a list of lists) and returns the sum of all the numbers anywhere in the structure: > (add-numbers '((4 calling birds) (5 gold rings) 10 (20 (30) 40))) 109
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/23/2010 for the course CS 61A taught by Professor Harvey during the Fall '08 term at University of California, Berkeley.

Page1 / 2

CS61A_sp92_mt2 - CS61A: Midterm #2-Spring 1992 CS61A,...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online