Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

"Little else matters than to write good code." -- Karl Lehenbauer


devel / comp.lang.awk / Syntax of function calls without arguments?

SubjectAuthor
* Syntax of function calls without arguments?Janis Papanagnou
+- Re: Syntax of function calls without arguments?Keith Thompson
`* Re: Syntax of function calls without arguments?Ivan Shmakov
 `* Re: Syntax of function calls without arguments?Ben Bacarisse
  `* Re: Syntax of function calls without arguments?Keith Thompson
   `- Re: Syntax of function calls without arguments?Ben Bacarisse

1
Syntax of function calls without arguments?

<u3hjb5$vo2j$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1452&group=comp.lang.awk#1452

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.lang.awk
Subject: Syntax of function calls without arguments?
Date: Thu, 11 May 2023 04:19:16 +0200
Organization: A noiseless patient Spider
Lines: 36
Message-ID: <u3hjb5$vo2j$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 11 May 2023 02:19:17 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="ea1f3870aaf300a04cf9a24a5f99c44c";
logging-data="1040467"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/DKQahz4ZWCAlgGNIv87RY"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:LfpVs/bv6YCxM+gFZU5ViLEudls=
X-Enigmail-Draft-Status: N1110
X-Mozilla-News-Host: news://news.eternal-september.org:119
 by: Janis Papanagnou - Thu, 11 May 2023 02:19 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.

Re: Syntax of function calls without arguments?

<87v8gza94o.fsf@nosuchdomain.example.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1453&group=comp.lang.awk#1453

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S.Thompson+u@gmail.com (Keith Thompson)
Newsgroups: comp.lang.awk
Subject: Re: Syntax of function calls without arguments?
Date: Wed, 10 May 2023 19:34:47 -0700
Organization: None to speak of
Lines: 52
Message-ID: <87v8gza94o.fsf@nosuchdomain.example.com>
References: <u3hjb5$vo2j$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="af23344badd732ee8eb21ba95e43a430";
logging-data="1042008"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX190Wunei7TdaTJQUq6mc8Nn"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:X1KClmP1P8eObDtjj6NVVLSDijs=
sha1:fz82RnlYj+cZiYbocmSSSI01qBQ=
 by: Keith Thompson - Thu, 11 May 2023 02:34 UTC

Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:
> 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.

gawk and mawk report a syntax error.

original-awk on Ubuntu accepts it:

$ original-awk --version
awk version 20180827
$ echo 2 | original-awk '{print sqrt}'
1.41421
$

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for XCOM Labs
void Void(void) { Void(); } /* The recursive call of the void */

Re: Syntax of function calls without arguments?

<u3jb3g$15fah$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1454&group=comp.lang.awk#1454

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!news.swapon.de!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ivan@siamics.netNOSPAM.invalid (Ivan Shmakov)
Newsgroups: comp.lang.awk
Subject: Re: Syntax of function calls without arguments?
Date: Thu, 11 May 2023 18:10:56 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 33
Message-ID: <u3jb3g$15fah$1@dont-email.me>
References: <u3hjb5$vo2j$1@dont-email.me>
Injection-Date: Thu, 11 May 2023 18:10:56 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="37dc1a2aa428bd9b4cf702d712c4f4a6";
logging-data="1228113"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Yo9tOv5lD/ZUKrKLGHp9b"
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:beJ1AKU/vG1n0dBol2v1pYj5BbY=
 by: Ivan Shmakov - Thu, 11 May 2023 18:10 UTC

>>>>> On 2023-05-11, Janis Papanagnou wrote:

> 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?

The one included in BusyBox 1.35.0 doesn't seem to accept it:

$ busybox awk '1 { print sqrt }'
awk: cmd. line:1: Unexpected token
$

The one from NetBSD, http://man.netbsd.org/awk.1 , does:

$ printf 2\\n | awk '1 { print sqrt }'
1.41421
$

> [*] 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.

--
FSF associate member #7257 http://am-1.org/~ivan/

Re: Syntax of function calls without arguments?

<87pm767iem.fsf@bsb.me.uk>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1455&group=comp.lang.awk#1455

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ben.usenet@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.awk
Subject: Re: Syntax of function calls without arguments?
Date: Thu, 11 May 2023 20:54:57 +0100
Organization: A noiseless patient Spider
Lines: 44
Message-ID: <87pm767iem.fsf@bsb.me.uk>
References: <u3hjb5$vo2j$1@dont-email.me> <u3jb3g$15fah$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="b65a419edaf6a21e7b445f839b9669d0";
logging-data="1263174"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18vltVUzfpBxQEnqsRqXHv5/tVDvgoJHtY="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
Cancel-Lock: sha1:BnaQtKMExk8tKFNs4DaTRnN+vC0=
sha1:C9A4Lb2/3k6B5j+ktYYG5KDmArQ=
X-BSB-Auth: 1.7c98f6004f45c82a998a.20230511205457BST.87pm767iem.fsf@bsb.me.uk
 by: Ben Bacarisse - Thu, 11 May 2023 19:54 UTC

Ivan Shmakov <ivan@siamics.netNOSPAM.invalid> writes:

>>>>>> On 2023-05-11, Janis Papanagnou wrote:
>
> > 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?
>
> The one included in BusyBox 1.35.0 doesn't seem to accept it:
>
> $ busybox awk '1 { print sqrt }'
> awk: cmd. line:1: Unexpected token
> $
>
> The one from NetBSD, http://man.netbsd.org/awk.1 , does:
>
> $ printf 2\\n | awk '1 { print sqrt }'
> 1.41421
> $

As does a version of Unix V7 awk running on a PDP11 simulator. It's
obviously an old feature:

$ echo 2 | awk '{print sqrt}'
1.41421

Curiously, it's only documented to apply to the length function. man
awk says

The built-in function length returns the length of its argu-
ment taken as a string, or of the whole line if no argument.
There are also built-in functions exp, log, sqrt, and int.

--
Ben.

Re: Syntax of function calls without arguments?

<87jzxea6o9.fsf@nosuchdomain.example.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1456&group=comp.lang.awk#1456

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S.Thompson+u@gmail.com (Keith Thompson)
Newsgroups: comp.lang.awk
Subject: Re: Syntax of function calls without arguments?
Date: Thu, 11 May 2023 14:40:06 -0700
Organization: None to speak of
Lines: 50
Message-ID: <87jzxea6o9.fsf@nosuchdomain.example.com>
References: <u3hjb5$vo2j$1@dont-email.me> <u3jb3g$15fah$1@dont-email.me>
<87pm767iem.fsf@bsb.me.uk>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="af23344badd732ee8eb21ba95e43a430";
logging-data="1285056"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19j00qLJCeTr/Mo+6pZOqKM"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:b+ikGhgvhXAn7h5fN/UkYz7bztE=
sha1:GFb45n7qcNUZvu3SWnvAaJ1dJ7Y=
 by: Keith Thompson - Thu, 11 May 2023 21:40 UTC

Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
> Ivan Shmakov <ivan@siamics.netNOSPAM.invalid> writes:
>
>>>>>>> On 2023-05-11, Janis Papanagnou wrote:
>>
>> > 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?
>>
>> The one included in BusyBox 1.35.0 doesn't seem to accept it:
>>
>> $ busybox awk '1 { print sqrt }'
>> awk: cmd. line:1: Unexpected token
>> $
>>
>> The one from NetBSD, http://man.netbsd.org/awk.1 , does:
>>
>> $ printf 2\\n | awk '1 { print sqrt }'
>> 1.41421
>> $
>
> As does a version of Unix V7 awk running on a PDP11 simulator. It's
> obviously an old feature:
>
> $ echo 2 | awk '{print sqrt}'
> 1.41421
>
> Curiously, it's only documented to apply to the length function. man
> awk says
>
> The built-in function length returns the length of its argu-
> ment taken as a string, or of the whole line if no argument.
> There are also built-in functions exp, log, sqrt, and int.

Just from that description, it's not clear that `length()` and `length`
are both valid.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for XCOM Labs
void Void(void) { Void(); } /* The recursive call of the void */

Re: Syntax of function calls without arguments?

<87wn1e5qc1.fsf@bsb.me.uk>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1457&group=comp.lang.awk#1457

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ben.usenet@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.awk
Subject: Re: Syntax of function calls without arguments?
Date: Fri, 12 May 2023 01:46:38 +0100
Organization: A noiseless patient Spider
Lines: 64
Message-ID: <87wn1e5qc1.fsf@bsb.me.uk>
References: <u3hjb5$vo2j$1@dont-email.me> <u3jb3g$15fah$1@dont-email.me>
<87pm767iem.fsf@bsb.me.uk> <87jzxea6o9.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="369c4b11a818ae9ae43a9e5d6f28a3be";
logging-data="1325918"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX180/Vyc660X3shzobqHlOuXxPvDRExP6nY="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
Cancel-Lock: sha1:Ll+0R7Eo+dX7FSlKvedQYf+QwWg=
sha1:7W2ARq6e+u56t5F/pgPZyq8oS/E=
X-BSB-Auth: 1.8f374c8f36b316221cc0.20230512014638BST.87wn1e5qc1.fsf@bsb.me.uk
 by: Ben Bacarisse - Fri, 12 May 2023 00:46 UTC

Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:

> Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
>> Ivan Shmakov <ivan@siamics.netNOSPAM.invalid> writes:
>>
>>>>>>>> On 2023-05-11, Janis Papanagnou wrote:
>>>
>>> > 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?
>>>
>>> The one included in BusyBox 1.35.0 doesn't seem to accept it:
>>>
>>> $ busybox awk '1 { print sqrt }'
>>> awk: cmd. line:1: Unexpected token
>>> $
>>>
>>> The one from NetBSD, http://man.netbsd.org/awk.1 , does:
>>>
>>> $ printf 2\\n | awk '1 { print sqrt }'
>>> 1.41421
>>> $
>>
>> As does a version of Unix V7 awk running on a PDP11 simulator. It's
>> obviously an old feature:
>>
>> $ echo 2 | awk '{print sqrt}'
>> 1.41421
>>
>> Curiously, it's only documented to apply to the length function. man
>> awk says
>>
>> The built-in function length returns the length of its argu-
>> ment taken as a string, or of the whole line if no argument.
>> There are also built-in functions exp, log, sqrt, and int.
>
> Just from that description, it's not clear that `length()` and `length`
> are both valid.

Indeed. The POSIX specification makes it clearer with

length[([s])] and "... if there is no argument"

The gawk man page writes length([s]) so its "if s is not supplied" is
not quite so clear. mawk's man page make no reference to the special
case at all.

I find it interesting that the special case of length applying to $0 has
been retained in modern AWKs, but not the general case. I'd have
thought it would have been simpler to do what the old AWK did. Maybe
too many bugs occurred from writing 'exp', but 'length' was too useful a
shorthand to outlaw.

--
Ben.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor