Given the following exercise:
Exercise 2.5
Show that we can represent pairs of nonnegative integers using only numbers and arithmetic operations if we represent the pair a and b as the integer that is the product 2^a * 3^b. Give the corresponding definitions of the procedures cons, car, and cdr.
I wrote the following:
(define (cons a b) (* (expt 2 a)
(expt 3 b)))
(define (car x)
(if (= 0 (remainder x 3))
(car (/ x 3))
(/ (log x)
(log 2))))
(define (cdr x)
(if (= 0 (remainder x 2))
(cdr (/ x 2))
(/ (log x)
(log 3))))
What do you think?