Next: Global Variables, Previous: Variables, Up: Variables [Contents][Index]
A variable whose name starts with a letter is a local variable.
Its scope is limited to the current context (user-defined subroutine or
function, or the main level). A particular variable that you define at
the main level of execution (i.e., at the ‘LUX>’ prompt) is not
known inside a user-defined subroutine or function. Likewise, a
variable that you define inside a particular user-defined subroutine or
function is not known inside any other subroutine or function, or at the
main execution level. This means that you can have different variables
with different values but the same name in different contexts. You can
define a variable x
at the main execution level, another x
inside your subroutine mysub
, and another x
inside your
subroutine dothis
, and all of these variables will be distinct.
You can access variables inside a subroutine or function from outside
that subroutine or function by prepending the name of the subroutine or
function and a period (.) to the name of the variable. In this
case the subroutine or function acts like a structure variable
(Structures). For instance, to inspect from the main execution
level the variable x
inside your subroutine mysub
, type
the following:
T,mysub.x
Of course, inside the subroutine the variable is called just x
.
This procedure does not work for parameters of user-defined functions
and subroutines: their value is lost when the routine is finished.
See also: Recursion