Reputation: 5971
What's wrong with this function?
(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))))
It doesn't return anything when i pass the arguments 3 5 4, in that order.
Upvotes: 2
Views: 88
Reputation: 9311
Why use cond
if you only put one branch inside it?
(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)))))
Upvotes: 3