1 (define (apply-generic op . args)
2 (define (can-coerce-into? types target-type)
4 (or (equal? type target-type)
5 (get-coercion type target-type)))
7 (define (find-coercion-target types)
10 (if (can-coerce-into? types target-type)
14 (define (coerce-all args target-type)
16 (let ((arg-type (type-tag arg)))
17 (if (equal? arg-type target-type)
19 ((get-coercion arg-type target-type) arg))))
21 (define (no-method type-tags)
22 (error "No method for these types"
24 (let ((type-tags (map type-tag args)))
25 (let ((proc (get op type-tags)))
27 (apply proc (map contents args))
28 (let ((target-type (find-coercion-target type-tags)))
33 (coerce-all args target-type)))
34 (no-method type-tags)))))))