0

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]

Alexander O'Mara
  • 58,688
  • 18
  • 163
  • 171

2 Answers2

2

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?)

C. K. Young
  • 219,335
  • 46
  • 382
  • 435
1

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))))
R Sahu
  • 204,454
  • 14
  • 159
  • 270