Note: this wiki is now retired and will no longer be updated!

The static final versions of the pages are left as a convenience for readers. Note that meta-pages such as "discussion," "history," etc., will not work.

SICP exercise 2.53

From Drewiki
Jump to: navigation, search

Contents

Problem

What would the interpreter print in response to evaluating each of the following expressions?

(list 'a 'b 'c)
 
(list (list 'george))
 
(cdr '((x1 x2) (y1 y2)))
 
(cadr '((x1 x2) (y1 y2)))
 
(pair? (car '(a short list)))
 
(memq 'red '((red shoes) (blue socks)))
 
(memq 'red '(red shoes blue socks))

Discussion

These solutions are straightforward. Recall from the text that memq returns #f if the symbol argument is not found in the list argument, otherwise it returns the sublist of the list beginning with the first occurrence of the symbol.

Solutions

Part 1

(list 'a 'b 'c)

Output:

(a b c)


Part 2

(list (list 'george))

Output:

((george))


Part 3

(cdr '((x1 x2) (y1 y2)))

Output:

((y1 y2))


Part 4

(cadr '((x1 x2) (y1 y2)))

Output:

(y1 y2)


Part 5

(pair? (car '(a short list)))

Output:

#f


Part 6

(memq 'red '((red shoes) (blue socks)))

Output:

#f


Part 7

(memq 'red '(red shoes blue socks))

Output:

(red shoes blue socks)
Personal tools