|
Home
>
3. concept
>
3.1 binding
>
3.1.4 module binding
>
3.1.4.1 what's the inverse of 'define variable ' and 'define method' ?
|
Previous
Next
|
|
|
|
|
|
Bruce Hoult
|
what's the inverse of 'define variable ' and 'define method' ?
i.e.
? foo;
error: unbound variable: foo.
** Debugger **
Debug[1]> [interrupt
-- returning to top level.]
? define variable foo = 99;
? foo;
==> 99
? WHATGOESHERE??
? foo;
error: unbound variable: foo.
** Debugger **
|
|
Seth LaForge
|
The point of define at the top level is that it creates a global binding.
There are two things you can do to get the effect you want:
- define the variable in it's own module (this prevents it from being
visible elsewhere, unless you specifically export it; or
- create a local binding using let.
Here's an example of the latter:
? foo;
error: unbound variable: foo.
? begin
> let foo = 99;
> foo;
> end;
==> 99
? foo;
error: unbound variable: foo.
?
|
|
|
|
|
|