Reputation: 13
I'm studying sicp. this question is ex 1.3. I can't understand why this code is problem. please help me.. TT
here's the code.
(define (test a b c)
(cond ((and (< a b) (< a c)) (+ (* b b) (* c c))
(and (< b a) (< b c)) (+ (* a a) (* c c))
(else (+ (* b b) (* c c)))
))
(test 1 2 3)
error is
Premature EOF on #[input-port 60 from buffer at #[mark 61 #[buffer 17] 166 left]
Upvotes: 0
Views: 1560
Reputation: 206717
Missing parentheses.
(define
(test a b c)
(cond
((and (< a b) (< a c)) (+ (* b b) (* c c)))
((and (< b a) (< b c)) (+ (* a a) (* c c)))
(else (+ (* b b) (* c c))))
Upvotes: 1
Reputation: 223183
Your syntax for cond
is wrong. Here is the same code with the correct syntax:
(define (test a b c)
(cond ((and (< a b) (< a c)) (+ (* b b) (* c c)))
((and (< b a) (< b c)) (+ (* a a) (* c c)))
(else (+ (* b b) (* c c)))))
However, your code is still wrong. Can you see why? (Hint: what does the else
branch signify, and what expression should be there?)
Upvotes: 2