【SICP练习】103 练习2.81-2.97

简介:

练习2-81

这里再次需要用到第186页的创建表格部分内容。当然了现在完全可以只是将make-table加载到这道题中。还有我们前面几题中用到的apply-generic。

a)
载入 Louis 的强制过程后,对两个复数调用exp会出现解释器假死的情况。

b)
Louis并没有纠正该问题,反而会让程序进入无限循环之中。

c)
解决这个错误的办法就是让apply-generic能够在其两个输入的参数的类型相同时让强制转换停止下来。

(define (apply-generic op . args)
    (let ((type-tags (map type-tag args)))
        (let ((proc (get op type-tags)))
            (if proc
                (apply proc (map contents args))
                (if (= (length args) 2) (let ((type1 (car type-tags)) (type2 (cadr type-tags)) (a1 (car args)) (a2 (cadr args))) (if (equal? type1 type2) (error "No method for these types" (list op type-tags)) (let ((t1->t2 (get-coercion type1 type2)) (t2->t1 (get-coercion type2 type1))) (cond (t1->t2 (apply-generic op (t1->t2 a1) a2)) (t2->t1 (apply-generic op a1 (t2->t1 a2))) (else (error "No method for these types" (list op type-tags))))))) (error "No method for these types" (list op type-tags)))))))

抱歉:剩余部分待完成。



感谢访问,希望对您有所帮助。 欢迎关注或收藏、评论或点赞。


为使本文得到斧正和提问,转载请注明出处:
http://blog.csdn.net/nomasp


目录
相关文章
|
机器学习/深度学习 算法