"Life is all about sharing. If we are good at something, pass it on." - Mary Berry

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 operation magnitude on the types (complex).

To simplify the install-complex-package procedure, I made the following changes:

 1(define (install-complex-package)
 2  (define (make-from-real-imag x y)
 3		((get 'make-from-real-imag 'rectangular) x y))
 4	(define (tag z) (attach-tag 'complex z))
 5	(put 'make-from-real-imag 'complex
 6		(lambda (x y) (tag (make-from-real-imag x y))))
 7
 8(install-complex-package)
 9
10(trace-define (make-complex-from-real-imag x y)
11	((get 'make-from-real-imag 'complex) x y))
12
13(magnitude (make-complex-from-real-imag 3 4))

Read More...