Blob


1 (define (apply-generic op . args)
2 (define (try-convert x new-type)
3 (let ((converter (get-coercion (type-tag x) new-type)))
4 (if converter
5 (converter x)
6 x)))
7 (define (apply-generic-1 op args type-list)
8 (if (null? type-list)
9 (error "No method for these types"
10 (list op (map type-tag args)))
11 (let ((new-args (map (lambda (x)
12 (try-convert x (car type-list)))
13 args)))
14 (let ((new-type-tags (map type-tag new-args)))
15 (let ((proc (get op new-type-tags)))
16 (if proc
17 (apply proc (map contents new-args))
18 (apply-generic-1 op args (cdr type-list))))))))
19 (let ((type-tags (map type-tag args)))
20 (let ((proc (get op type-tags)))
21 (if proc
22 (apply proc (map contents args))
23 (apply-generic-1 op args type-tags)))))