0
votes

For Scheme, I know that variables are either bound or free. This makes sense to me, but only in the context of when we're talking about variables that are the formal parameters of procedures. A bound variable is one that is bound to a procedure as a formal parameter, thus its scope is the procedure, and the name of the variable can be changed without affecting anything. A free variable is one that is not bound in the context of one procedure, but that is bound in some containing procedure. This I understand, but when we define variables not as formal parameters, but as containers of values, i.e. (define size 2), how could size be bound or free if it is not a formal parameter of a procedure?

1

1 Answers

1
votes

Size is bound at the top level of an interactive Scheme system, also called the REPL.

Almost everything about the top level is unspecified in Scheme standards prior to R7RS. The REPL is mentioned for the first time in the Scheme standards in section 5.7 of the R7RS Report, but everything that is specified is "may" rather than "shall" so it's not really standard, more a matter of convenience, and most Scheme implementations extend the top level in some way.

Thus, a top-level definition like (define size 2) binds size in the top level, and in anything that inherits from the top level.