Home Manual Packages Global Index Keywords Quick Reference |
> ### 1.2.5 Variable scope By default, dummy parameters and variables which are defined in a function body before any other use are local variables. Variables (or functions) used before their definition are external variables (see section 1.2.2 Defining Procedures, see section 1.2.1 Defining a function). A variable (or function) defined outside of all functions is just that -- external to all functions and local to none. Whenever a function is called, Yorick remembers the external values of all its local variables, then replaces them by their local values. Thus, all of its local variables are potentially "visible" as external variables to any function it calls. When it returns, the function replaces all its local variables by the values it remembered. Neither that function, nor any function it calls can affect these remembered values; Yorick provides no means of "unmasking" a local variable. The default rule for determining whether a variable should have local or external scope fails in two cases: First, you may want to redefine an external variable without looking at its value. Second, a few procedures set the values of their parameters when they return; it may appear to Yorick's parser that such a variable has been used without being defined, even though you intend it to be local to the function. The `extern` and `local` statements solve these two problems, respectively.
> 1.2.5.1 `extern` statements |  |
> 1.2.5.2 `local` statements |  |