2011-10-14 4 views
2

이 기능에 문제가 있습니까?다음과 같은 구성표 코드에 무슨 문제가 있습니까?

(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를이 순서로 전달할 때 아무 것도 반환하지 않습니다.

답변

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))))) 
관련 문제