-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex-2.85.scm
47 lines (39 loc) · 991 Bytes
/
ex-2.85.scm
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
(define (project x)
(let ((proc (get 'project (list (type-tag x)))))
(if proc
(proc x)
#f)))
(put 'project '(complex)
(lambda (c)
(make-real (real-part c))))
(put 'project '(real)
(lambda (r) round))
(put 'project '(rational)
(lambda (r)
(round
(/ (numer r)
(denom r)))))
; (define (drop x)
; (if (get 'project (list (type-tag x)))
; (let ((px (project x)))
; (if (equ? x (raise px))
; (drop px)
; x))
; x))
(define (drop x)
(let ((px (project x)))
(if (and px
(equ? x (raise px)))
(drop px)
x)))
(define (apply-generic op . args)
(let ((type-tags (map type-tag args)))
(let ((proc (get op type-tags)))
(if proc
(drop
(apply proc (map contents args)))
(apply-generic
op
(apply raise-args-one-step args))))))
(define (apply-generic op . args)
(drop (apply apply-generic-2.84 (cons op args))))