{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

CS61A_sp92_mt2

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

Info icon This 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 Question 4 (5 points): This two-part question is about data-directed programming. We are going to use a list to represent a
Image of page 1

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern