4 days ago

my attempt to do the exercises in sicp.

## Tuesday, August 12, 2008

### sicp exercise 2.83

;; Exercise 2.83. Suppose you are designing a generic arithmetic system for dealing with the tower of types shown in figure 2.25: integer, rational, real, complex. For each type (except complex), design a procedure that raises objects of that type one level in the tower. Show how to install a generic raise operation that will work for each type (except complex).

(define (install-rational-number-package)

;;...

(define (raise rat-num)

(make-complex-from-real-imag rat-num 0))

(put 'raise '(rational) raise)

'done)

(define (install-scheme-number-package)

;;...

(define (raise number)

(make-rat number 1))

(put 'raise '(scheme-number) raise)

'done)

(define (raise num)

(apply-generic 'raise num))

Subscribe to:
Post Comments (Atom)

## No comments:

Post a Comment