Blob


1 (define (make-from-real-imag x y)
2 (define (dispatch op)
3 (cond ((eq? op 'real-part) x)
4 ((eq? op 'imag-part) y)
5 ((eq? op 'magnitude)
6 (sqrt (+ (square x) (square y))))
7 ((eq? op 'angle) (atan y x))
8 (else (error "Unknown op -- MAKE-FROM-REAL-IMAG" op))))
9 dispatch)
11 (define (apply-generic op arg) (arg op))
13 ;; Exercise 2.75. Implement the constructor make-from-mag-ang in message-passing style. This procedure should be analogous to the make-from-real-imag procedure given above.
15 (define (make-from-mag-ang r a)
16 (define (dispatch op)
17 (cond ((eq? op 'real-part) (* r (cos a)))
18 ((eq? op 'imag-part) (* r (sin a)))
19 ((eq? op 'magnitude) r)
20 ((eq? op 'angle) a)
21 (else (error "Unknown op -- MAKE-FROM-REAL-IMAG" op))))
22 dispatch)