Re:The Awk Programming Language (1988) [pdf]
by coliveira on Thursday May 24, 2018 @02:03PM
(#17146611)
Actually what you show is that there is a clear rule. First, the symbol is treated as a function. If it is not in the function space, then it is used as a variable name. To make a finer distinction awk would need some form of local variable declaration, which it clearly hasn't.
[ Parent
| on HN ]
Re:The Awk Programming Language (1988) [pdf]
by kazinator on Thursday May 24, 2018 @03:58PM
(#17147718)
> First, the symbol is treated as a function. If it is not in the function space, then it is used as a variable name.
That is simply not the case. x() unambiguously treats x as a function, and will fail if there is no such function, even if there is a variable x.
$ awk 'function foo(x)
{
x()
}
BEGIN { foo(42) }'
awk: cmd. line:2: fatal: function `x' not defined
> To make a finer distinction awk would need some form of local variable declaration, which it clearly hasn't.Also not the case. The purely syntactic context distinguishes whether or not the identifier is being used as a variable or function. Awk sometimes uses it, sometimes not. This doesn't diagnose:
function x()
{
}
function foo(x)
{
x() # function call allowed
x = 3 # assignment allowed
}
BEGIN { foo(42) }
But: function foo(x)
{
}
BEGIN { foo = 3 }
fatal: function `foo' called with space between name and `(',
or used as a variable or an array
Why isn't it a problem that the function x() is used as a variable?