My Computer Science 1901 class uses MIT Scheme as its language of choice. While working in a lab yesterday, I ran across this error message.
Can’t bind name in null syntactic environment
My code looked similar to this example.
(define a 5) (define b 10) (if (> a b) (define x a) (define x b) )
Notice the define statements in the if-statement? Well, that’s illegal. The problem is that the if-statement has its own temporary scope or environment in the professional schemer lingo.
To fix this problem, I switched my approach. Instead of defining the values inside the if, I could define the value with an if itself.
(define a 5) (define b 10) (define x (if (> a b) a b) )
And this works just fine, x is set to the return value of the if expression’s evaluation. It’s that easy.