[plt-scheme] Reference to an identifier before its definition

From: Thomas Chust (chust at web.de)
Date: Wed Apr 14 08:14:58 EDT 2010

2010/4/14 Ferreira Maurizio <maurizio.ferreira at seling.it>:
> [...]
> Are forward references to definitions allowed ?
> [...]

Hello Maurizio,

the scope of an identifier used in a definition extends over all
expressions on the same level, but the value bound to the identifier
can only be accessed after the definition has been executed.

Thus you can use forward references to definitions in places like
procedure bodies, where the identifier must be known at compile time
but the value bound to it is only accessed later, when the procedure
is executed. However, using a forward reference in a place like the
expression to be evaluated to determine the binding of another
definition won't work -- these expressions are evaluated in sequence
and even though the identifier used in the forward reference is known,
its binding has not been determined, yet.

Basically the reason for this restriction is that Scheme doesn't use
lazy evaluation by default ;-)

Ciao,
Thomas


-- 
When C++ is your hammer, every problem looks like your thumb.


Posted on the users mailing list.