local
localvar1 [, var2 …]
The local statement (command) declares one or more scalar or array variables local to the current block, which ends with the enclosing '}'. It has the same syntax as the global statement.
A scalar variable can be given an initial value by assignment using the form var = expr; see the examples that follow. If no initial value is given the variable will be initialized to null.
An array is declared by appending "[]" to the variable name. In this case the array can be either a normal or associative array depending on context and will grow as necessary. A fixed size normal (that is, non-associative) array may be declared by specifying the size of the array inside the brackets, for example, arry[10]. The size may be an expression, which is evaluated at run time. The size is also the upper bound of the array since the first subscript is 1. To declare a fixed size array with a different minimum subscript, use the form
localarr[lb.. hb]
where lb and hb are expressions giving the low and high bounds of the array. Arbortext Editor will report a run-time error if you attempt to index outside the bounds of a fixed-size array.
|
local is an executable statement, so that initial values get evaluated each time the command is executed. This also means that for best efficiency it is better to not use local commands inside loops which execute many times.
|
It is an error to declare a local variable which was previously defined at the current level. See the following sample function.
The local command is only allowed inside function definitions.
Examples
function f(x, src[])
{
local doc, save_doc = current_doc()
local assoc[]; # declare associative array
local dest[count(src)];# declare dest same size as src
local x; # illegal, hides parameter
local m=1
{
local m=2; # ok
local x[]; # ok
}
local m; # illegal, hides previous value
}
Related Topics