local
local { statements; }
local () statement;
local () { statements; }
In the statement or code block following the local function, all new variables defined are local variables as long this function is not called
from a main program with global variables scope, i.e. outside code in user-defined functions and progams not started with start() or include().
In this case, global variables are defined instead. In other words, local variables will always be created, even if global variables exist with same names.
Note: The rules are not applicable for system variables. Insie the local code block, system variables can be read, written and member variables of them
can be created. Only write-access to global variables are prevented.
Indirect parameter passing is disabled
0
country[] = France;
define procedure( do locally )
{
echo(" Inside 'do locally' function before assignment: ", country[] );
local() country[] = Spain; // Create a local variable, do not overwrite global variable with same name
local() runtime settings[epsilon] = 0.1; // This is a system variable
echo(" Inside 'do locally' function after assignment: ", country[], new line );
}
define procedure( do globally )
{
echo(" Inside 'do globally' function before assignment: ", country[] );
country[] = Portugal; // Create a local variable, do not overwrite global variable with same name
echo(" Inside 'do globally' function after assignment: ", country[], new line );
}
echo("Outside function: ", country[] );
do locally;
echo("Outside function: ", country[] );
do globally;
echo("Outside function: ", country[] );
// Verify that system variables can be changed even in local-encorced code.
echo("Runtime settings - Epsilon: ", runtime settings[epsilon] ); // Value set to 0.1 in 'do locally()'
Outside function: France
Inside 'do locally' function before assignment: France
Inside 'do locally' function after assignment: Spain
Outside function: France
Inside 'do globally' function before assignment: France
Inside 'do globally' function after assignment: Portugal
Outside function: Portugal
Runtime settings - Epsilon: 0.1