Sample Questions: SICP Section 2.1
Data Abstraction
Rational numbers

Suppose the rational constructor makerat could be passed
both integers and rational numbers. How could the constructor
identify the type of its arguments in order to simply its
result?
Choose the most complete answer.
 use integer? or pair?
 use pair?
 use integer?
 neither

Suppose the rational constructor makerat could be passed
both integers and rational numbers. How many cases must
the constructor handle in order to simply its
result?
 3
 4
 1
 6
 2
 7
 5
 8

Suppose the rational constructor makerat could be passed
both integers and rational numbers. Define an expression
that the constuctor could use to
simpify the resultion numerator in
the rationalrational case.
Use the variables nn and dn to refer to the numerator of the numerator
and the denominator of the numerator, respectively. Likewise for
nd and dd.
Implementing fundamental types

With this implementation for cons:
(define (cons a b) (lambda (w) (w a b)))
which of the following would be a valid implementation of car?

(define (car c) (lambda (x y) x))

(define (car c) (lambda (c) (c (lambda (x y) x))))

(define (car c) (c (lambda (x y) x)))

(define (car c) (c c))

With this implementation for cons, which only works for integers:
(define (cons a b) (* (^ 2 a) (^ 3 b)))
which of the following would is a valid implementation of car?
Assume
^
is the exponentiation function and that when given two integers,
returns an integer.
Assume
(ilog b d)
returns the closest integer to $lo{g}_{b}d$.

(define (car x) (ilog x 2))

(define (car x) (if (= (% x 2) 0) 0 (+ 1 (car (/ x 2)))))

(define (car x) (if (= (% x 2) 0) (ilog 3 x) (car (/ x 2))))

(define (car x) (if (!= (% x 3) 0) (ilog 2 x) (car (/ x 3))))

Given the following incrementer and base:
(define (inc x) 1)
(define base (lambda (y) (+ 1 y)))
and the evaluation of the Church numbers four:
(define x ((four inc) base))
What is the value of x?

(lambda (y) (+ 1 y))
 4
 5
 1

Which are valid functions for adding two Church numerals?
(define (add a b)
(lambda (f)
(lambda (x)
((((a add1) b) f) x)
)
)
)
(define (add a b)
(lambda (f)
(lambda (x)
((a f) ((b f) x))
)
)
)
 both
 the second
 the first
 neither