SICP Study

4B Generic Operators

Part 1

Limits of data abstraction

Complex number arithmetic

x=rcosθ,r=x2+y2,y=rsinθ,θ=arctan(y,x).\begin{aligned} x &= r\cos θ, & r &= \sqrt{x^2+y^2}, \\ y &= r\sin θ, & θ &= \arctan(y, x). \end{aligned}

Incompatible representations

Part 2

Problems with the manager

Data-directed programming

(define (operate op obj)
  (let ((proc (get (type obj) op)))
    (if (null? proc)
        (error "undefined operator")
        (proc (contents obj)))))
(real-part z)
(operate 'real-part z)
((get 'polar 'real-part) (contents z))
(real-part-polar '(1 . 2))
(* 1 (cos 2))
-0.4161468365

Part 3

Generic arithmetic system

Polynomials

Conclusion