A define
outside of the top-level is called an internal definition. Internal definitions do not create top/module-level bindings; instead, they're syntactic sugar for an equivalent letrec*
expression. That means that the bindings created by the internal definitions are visible only within the lambda/scope where the internal definitions live; in your case, that means they are visible only within the (let () ...)
.
In particular, this means that you cannot conditionally define variables the way you were trying to do in your cond
. Remember that (since you're already using an imperative programming style) you can just create top-level bindings set initially to #f
(or some other blank value, though #f
is customary), and then conditionally set!
them to the values you want.
Beyond that, there are many other things wrong with your code. For example:
- Don't compare numbers using
eq?
, use=
. - Don't use parentheses around the
else
; that's invalid. - Inside the
else
branch, you had a number ofdefine
forms that are invalid. Remember you cannot conditionally define new variables. - Your
genSuccessors
has way too manycond
expressions. You want to have one singlecond
expression with many branches within it. Also you need to break up your branch conditions into multiple lines for easier reading.