Thursday, June 4, 2009

Ex-2.5

This is another interesting way to implelment pairs for non-negative integers.
(define (cons a b)
(* (expt 2 a) (expt 3 b)))
(define (car z)
(define (iter a count)
(if (= (remainder a 2) 0)
(iter (quotient a 2) (+ count 1))
count))
(iter z 0))
(define (cdr z)
(define (iter a count)
(if (= (remainder a 3) 0)
(iter (quotient a 3) (+ count 1))
count))
(iter z 0))

No comments:

Post a Comment