|
|
|
|
|
by kazinator
2326 days ago
|
|
Awk has funtions with named parameters. Local variables unfortunately can only be obtained in the form of extra parameters (which are not passed by the caller). function foo(x, y, # params
z, w) # locals
{
}
There is a convention to separate the two by some obvious whitespace.There are no block scoped-locals: all locals have to go into the parameter list. Initial values cannot be specified. (Speaking of which, there are hacks for simulating the feature of optional parameters with defaulted values.) In GNU Awk, from the following experiment, the scope appears lexical: function bar()
{
return x
}
function foo(x)
{
x = 3
return bar();
}
BEGIN { x = 42; print foo(); }
The output is 42, which means that the "x = 3" assignment to the local variable x in foo does not affect the access to the free variable x in bar, as it would under dynamic scope. |
|