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 2a 3b. Give the corresponding definitions of the procedures cons, car, and cdr.

 

(define (quotient-iter p n k)
(if (= (remainder p n) 0)
(quotient-iter (quotient p n) n (+ k 1))
k))
(define (pair23 a b)
(* (expt 2 a) (expt 3 b)))
(define (x-coord p)
(quotient-iter p 2 0))
(define (y-coord p)
(quotient-iter p 3 0))
view raw s205.scm hosted with ❤ by GitHub