(define (square-sum-larger a b c)
(cond ((and (< a b) (< a c))) (+ (* b b) (* c c))) ;; this is thrown away
(cond ((and (< b c) (< b a))) (+ (* a a) (* c c))) ;; this is thrown away
(cond ((and (< c a) (< c b))) (+ (* b b) (* a a)))
)
只有最后一个
cond
做任何有用的事;前一个
康德
表达式没有任何副作用,因为它们只执行计算,不使用它们的值。方案编译器可以完全消除这些死代码。
你可能想把所有的子句合并成一个条件:
(define (square-sum-larger a b c)
(cond ((and (< a b) (< a c))) (+ (* b b) (* c c))
((and (< b c) (< b a))) (+ (* a a) (* c c))
((and (< c a) (< c b))) (+ (* b b) (* a a))))