Search code examples
schemesicp

Error: Can't bind name in null syntactic environment


I'm currently going through exercise 1.3 of the sicp book. Here's the description of the problem:

Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers.

I tried to solve it with the following code

(define (square x) (* x x))

(define (sq2largest a b c)
        ((define large1 (if (> a b) a b)) 
         (define small  (if (= large1 a) b a))
         (define large2 (if (> c small) c small))
         (+ (square large1) (square large2))))

When I ran it in mit-scheme, I got the following error:

;Can't bind name in null syntactic environment: large1 #[reserved-name-item 13]

Googling this error doesn't yield many results. Does anyone know what's wrong with my code? (I'm not familiar with Scheme)


Solution

  • You have too many brackets. If you took out the extra brackets around the internal defines, things should work a lot better.