这个功能出了什么问题?
(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时,它不会返回任何内容。
答案 0 :(得分:3)
如果只在其中放入一个分支,为什么要使用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)))))