Given the following problem (SICP Exercise 1.3):
Define a procedure that takes three numbers as arguments and returns the sum of squares of the two largest numbers.
I wrote the following (somewhat clumsy) solution in Scheme. How can I make it better?
(define (greatest-two a b c) (cond ((> a b) (cond ((> b c) (list a b)) (else (list a c)))) ((> a c) (cond ((> c b) (list a c)) (else (list a b)))) (else (list b c)))) (define (square x) (* x x)) (define (sum-of-squares a b) (+ (square a) (square b))) (define (f a b c) (apply sum-of-squares (greatest-two a b c)))