-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path2_79.rkt
26 lines (22 loc) · 954 Bytes
/
2_79.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#lang racket
#| Solution for exercise 2_79. |#
(require "./2_78.rkt")
(require (only-in "../solutions/2_78.rkt" install-scheme-number-package install-rational-package install-complex-package))
(require (only-in "../solutions/dispatch-table.rkt" put get apply-generic))
(provide install-equ?-package)
(define (install-equ?-package)
(define real-part (get 'real-part '(complex)))
(define imag-part (get 'imag-part '(complex)))
(define numer (get 'numer '(rational)))
(define denom (get 'denom '(rational)))
(define (equ? x y) (apply-generic 'equ? x y))
(put 'equ? '(scheme-number scheme-number) =)
(put 'equ? '(rational rational)
(lambda (rat1 rat2)
(and (equ? (numer rat1) (numer rat2))
(equ? (denom rat1) (denom rat2)))))
(put 'equ? '(complex complex)
(lambda (x y)
(and (equ? (real-part x) (real-part y))
(equ? (imag-part x) (imag-part y)))))
'install-equ?-package-done)