这个函数有什么问题吗?
(define (get-two-largest a b c)
(cond ((and (>= a b) (>= a c)) (if (> b c) (list a b) (list a c))))
(cond ((and (>= b a) (>= b c)) (if (> a c) (list b a) (list b c))))
(cond ((and (>= c a) (>= c b)) (if (> a b) (list c a) (list c b))))
当我按顺序传递参数 3 5 4 时,它不会返回任何内容。
最佳答案
如果只在其中放入一个分支,为什么要使用 cond
?
(define (get-two-largest a b c)
(cond ((and (>= a b) (>= a c)) (if (> b c) (list a b) (list a c)))
((and (>= b a) (>= b c)) (if (> a c) (list b a) (list b c)))
((and (>= c a) (>= c b)) (if (> a b) (list c a) (list c b)))))
关于scheme - 下面的方案代码有什么问题吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7766289/