SICP Exercise 2.77: expected a procedure that can be applied to arguments, given #f
2023-07-13
2.5.1 Generic Arithmetic Operations
Louis Reasoner tries to evaluate the expression (magnitude z) where z is the object shown in figure 2.24. To his surprise, instead of the answer 5 he gets an error message from
apply-generic, saying there is no method for the operationmagnitudeon the types(complex).
To simplify the install-complex-package procedure, I made the following changes:
(define (install-complex-package)
(define (make-from-real-imag x y)
((get 'make-from-real-imag 'rectangular) x y))
(define (tag z) (attach-tag 'complex z))
(put 'make-from-real-imag 'complex
(lambda (x y) (tag (make-from-real-imag x y))))
(install-complex-package)
(trace-define (make-complex-from-real-imag x y)
((get 'make-from-real-imag 'complex) x y))
(magnitude (make-complex-from-real-imag 3 4))
Quan Tong