Janis Papanagnou
2023-05-11 02:19:16 UTC
In an old paper "Awk - A Pattern Scanning and Processing Language"[*]
from the authors of Awk I read:
"Awk also provides the arithmetic functions sqrt, log, exp, and
int, for square root, base e logarithm, exponential, and integer
part of their respective arguments.
The name of one of these built-in functions, _without argument or
parentheses_, stands for the value of the function on the whole
record."
POSIX[**] says:
"Although the grammar (see Grammar) permits built-in functions to
appear _with no arguments or parentheses_, [...], such use is
undefined."
(_emphasis_ in the quotes added by me).
GNU Awk (for example) typically[***] returns errors:
$ awk '{print sqrt}'
awk: cmd. line:1: {print sqrt}
awk: cmd. line:1: ^ syntax error
$ awk '{print sqrt()}'
awk: cmd. line:1: {print sqrt()}
awk: cmd. line:1: ^ 0 is invalid as number of arguments for sqrt
How do other Awks behave? - I'd assume that "oawk" and "nawk" might
support that feature, but does any other awk implementation support
that?
Janis
[*] https://people.eecs.berkeley.edu/~clancy/sp.unix.stuff/awk
[**] https://pubs.opengroup.org/onlinepubs/9699919799/utilities/awk.html
[***] With length($0), length(), length as a singular(?) exception.
from the authors of Awk I read:
"Awk also provides the arithmetic functions sqrt, log, exp, and
int, for square root, base e logarithm, exponential, and integer
part of their respective arguments.
The name of one of these built-in functions, _without argument or
parentheses_, stands for the value of the function on the whole
record."
POSIX[**] says:
"Although the grammar (see Grammar) permits built-in functions to
appear _with no arguments or parentheses_, [...], such use is
undefined."
(_emphasis_ in the quotes added by me).
GNU Awk (for example) typically[***] returns errors:
$ awk '{print sqrt}'
awk: cmd. line:1: {print sqrt}
awk: cmd. line:1: ^ syntax error
$ awk '{print sqrt()}'
awk: cmd. line:1: {print sqrt()}
awk: cmd. line:1: ^ 0 is invalid as number of arguments for sqrt
How do other Awks behave? - I'd assume that "oawk" and "nawk" might
support that feature, but does any other awk implementation support
that?
Janis
[*] https://people.eecs.berkeley.edu/~clancy/sp.unix.stuff/awk
[**] https://pubs.opengroup.org/onlinepubs/9699919799/utilities/awk.html
[***] With length($0), length(), length as a singular(?) exception.