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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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)) | |