Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

The amount of weight an evangelist carries with the almighty is measured in billigrahams.


devel / comp.lang.awk / Re: Awk output redirection to expression - defined or not?

SubjectAuthor
* Awk output redirection to expression - defined or not?Ed Morton
`* Re: Awk output redirection to expression - defined or not?Janis Papanagnou
 `* Re: Awk output redirection to expression - defined or not?Ed Morton
  `- Re: Awk output redirection to expression - defined or not?Janis Papanagnou

1
Awk output redirection to expression - defined or not?

<u4nret$3gtc9$2@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: mortonspam@gmail.com (Ed Morton)
Newsgroups: comp.lang.awk
Subject: Awk output redirection to expression - defined or not?
Date: Thu, 25 May 2023 09:30:53 -0500
Organization: A noiseless patient Spider
Lines: 54
Message-ID: <u4nret$3gtc9$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 25 May 2023 14:30:53 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="9381c96c7dd1abbde3e3ee46f29726b6";
logging-data="3700105"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/zkRvegGdvEBXsEROmXqP1"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:/f7fbjTQp2z4gkkW70+kKABP6CU=
X-Antivirus: Avast (VPS 230524-12, 5/24/2023), Outbound message
Content-Language: en-US
X-Antivirus-Status: Clean
 by: Ed Morton - Thu, 25 May 2023 14:30 UTC

I'm certain I remember years ago reading a document that said
(paraphrasing) "an unparenthesized expression on the right side of input
or output redirection is undefined behavior" and I thought it was an
older version of the POSIX spec. I now can't find that (or similar)
statement in any of these:

SUSV2 - https://pubs.opengroup.org/onlinepubs/7990989775/xcu/awk.html
SUSV3 -
https://pubs.opengroup.org/onlinepubs/009695399/utilities/awk.html
Current POSIX spec -
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/awk.html

or by googling.

What I do see in the current POSIX spec is a related statement just
about input redirection:

> Historical practice has been that:
> getline < "a" "b"
>
> is parsed as:
> ( getline < "a" ) "b"
>
> although many would argue that the intent was that the file ab should
be read. However:
> getline < "x" + 1
>
> parses as:
> getline < ( "x" + 1 )
>
> ...
> Since in most cases such constructs are not (or at least should not)
be used (because they have a natural ambiguity for which there is no
conventional parsing), the meaning of these constructs has been made
explicitly unspecified.

and:

> The getline operator can form ambiguous constructs when there are
unparenthesized binary operators (including concatenate) to the right of
the '<' (up to the end of the expression containing the getline). The
result of evaluating such a construct is unspecified

but nothing about output redirection. I know gawk doesn't require parens
around the expression for output redirection but other awks do (e.g. see
https://stackoverflow.com/q/21093626/1745001) and it's not obvious to me
why `getline < "a" "b"` should be undefined behavior while `print > "a"
"b"` wouldn't be so intuitively if one of them is undefined then so
should the other be.

Does anyone else recall seeing a statement about output redirection to
an expression requiring parens and, if so, do you recall where it existed?

Ed.

Re: Awk output redirection to expression - defined or not?

<u4nvbq$3i31i$1@dont-email.me>

  copy mid

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

  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@hotmail.com (Janis Papanagnou)
Newsgroups: comp.lang.awk
Subject: Re: Awk output redirection to expression - defined or not?
Date: Thu, 25 May 2023 17:37:30 +0200
Organization: A noiseless patient Spider
Lines: 86
Message-ID: <u4nvbq$3i31i$1@dont-email.me>
References: <u4nret$3gtc9$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 25 May 2023 15:37:30 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="04de0651ab48c021042bb5ae03ef412e";
logging-data="3738674"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/NaAt8feeJnECP5lsYOTGs"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:LttygMflfPGG2Hp8keVKzzka17c=
Content-Language: en-US
In-Reply-To: <u4nret$3gtc9$2@dont-email.me>
 by: Janis Papanagnou - Thu, 25 May 2023 15:37 UTC

On 25.05.23 16:30, Ed Morton wrote:
> I'm certain I remember years ago reading a document that said
> (paraphrasing) "an unparenthesized expression on the right side of input
> or output redirection is undefined behavior" and I thought it was an
> older version of the POSIX spec. I now can't find that (or similar)
> statement in any of these:
>
>     SUSV2 - https://pubs.opengroup.org/onlinepubs/7990989775/xcu/awk.html
>     SUSV3 -
> https://pubs.opengroup.org/onlinepubs/009695399/utilities/awk.html
>     Current POSIX spec -
> https://pubs.opengroup.org/onlinepubs/9699919799/utilities/awk.html
>
> or by googling.
>
> What I do see in the current POSIX spec is a related statement just
> about input redirection:
>
> > Historical practice has been that:
> > getline < "a" "b"
> >
> > is parsed as:
> > ( getline < "a" ) "b"
> >
> > although many would argue that the intent was that the file ab should
> be read. However:
> > getline < "x" + 1
> >
> > parses as:
> > getline < ( "x" + 1 )
> >
> > ...
> > Since in most cases such constructs are not (or at least should not)
> be used (because they have a natural ambiguity for which there is no
> conventional parsing), the meaning of these constructs has been made
> explicitly unspecified.
>
> and:
>
> > The getline operator can form ambiguous constructs when there are
> unparenthesized binary operators (including concatenate) to the right of
> the '<' (up to the end of the expression containing the getline). The
> result of evaluating such a construct is unspecified
>
> but nothing about output redirection. I know gawk doesn't require parens
> around the expression for output redirection but other awks do (e.g. see
> https://stackoverflow.com/q/21093626/1745001) and it's not obvious to me
> why `getline < "a" "b"` should be undefined behavior while `print > "a"
> "b"` wouldn't be so intuitively if one of them is undefined then so
> should the other be.
>
> Does anyone else recall seeing a statement about output redirection to
> an expression requiring parens and, if so, do you recall where it existed?

What I recall is that a few times there were discussions about that,
but there was (AFAIR) never a formal explanation.

My thoughts about your question above are as follows...

getline expressions might consider precedence rules, and since in
C-like languages (as opposed to e.g. Algol68) have the precedence
associated with the concrete symbol ('<', '>') as opposed to the
semantic context, so 'less than' would bind stronger than 'concat'.
In cases where (as quoted above) "conventional parsing" deviates
from that (whatever "conventional" or "non-conventional" will be)
it might be different.

Note also that I wrote "getline *expressions*" as opposed to, say,
"print *statement*"; getline is part of the expression (it has a
value) where print has an expression argument. There is (I think)
no expression that starts with '>' in awk, so 'print >' should be
a redirection indication, generally.

Depending on semantical context an expression
if (getline < "a" + i) ...
can make sense in both cases, try reading from "a" and adding a
constant to the return value, or reading from "a1", "a42", etc.

So I can see why one is undefined but not the other. And my coding
approach would be to make the intention visible by parenthesis.

Janis

>
>     Ed.

Re: Awk output redirection to expression - defined or not?

<u4vma2$svhp$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: mortonspam@gmail.com (Ed Morton)
Newsgroups: comp.lang.awk
Subject: Re: Awk output redirection to expression - defined or not?
Date: Sun, 28 May 2023 08:52:03 -0500
Organization: A noiseless patient Spider
Lines: 102
Message-ID: <u4vma2$svhp$1@dont-email.me>
References: <u4nret$3gtc9$2@dont-email.me> <u4nvbq$3i31i$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 28 May 2023 13:52:02 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="29baeeee068d9fa2ac810de96419d3d5";
logging-data="949817"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/hYdM7k4nEqZlMLA+i+m64"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:NPXkkYsOAO59J0wWqiz58xXhN60=
X-Antivirus: Avast (VPS 230528-6, 5/28/2023), Outbound message
In-Reply-To: <u4nvbq$3i31i$1@dont-email.me>
Content-Language: en-US
X-Antivirus-Status: Clean
 by: Ed Morton - Sun, 28 May 2023 13:52 UTC

On 5/25/2023 10:37 AM, Janis Papanagnou wrote:
> On 25.05.23 16:30, Ed Morton wrote:
>> I'm certain I remember years ago reading a document that said
>> (paraphrasing) "an unparenthesized expression on the right side of
>> input or output redirection is undefined behavior" and I thought it
>> was an older version of the POSIX spec. I now can't find that (or
>> similar) statement in any of these:
>>
>>      SUSV2 -
>> https://pubs.opengroup.org/onlinepubs/7990989775/xcu/awk.html
>>      SUSV3 -
>> https://pubs.opengroup.org/onlinepubs/009695399/utilities/awk.html
>>      Current POSIX spec -
>> https://pubs.opengroup.org/onlinepubs/9699919799/utilities/awk.html
>>
>> or by googling.
>>
>> What I do see in the current POSIX spec is a related statement just
>> about input redirection:
>>
>>  > Historical practice has been that:
>>  > getline < "a" "b"
>>  >
>>  > is parsed as:
>>  > ( getline < "a" ) "b"
>>  >
>>  > although many would argue that the intent was that the file ab
>> should be read. However:
>>  > getline < "x" + 1
>>  >
>>  > parses as:
>>  > getline < ( "x" + 1 )
>>  >
>>  > ...
>>  > Since in most cases such constructs are not (or at least should
>> not) be used (because they have a natural ambiguity for which there is
>> no conventional parsing), the meaning of these constructs has been
>> made explicitly unspecified.
>>
>> and:
>>
>>  > The getline operator can form ambiguous constructs when there are
>> unparenthesized binary operators (including concatenate) to the right
>> of the '<' (up to the end of the expression containing the getline).
>> The result of evaluating such a construct is unspecified
>>
>> but nothing about output redirection. I know gawk doesn't require
>> parens around the expression for output redirection but other awks do
>> (e.g. see https://stackoverflow.com/q/21093626/1745001) and it's not
>> obvious to me why `getline < "a" "b"` should be undefined behavior
>> while `print > "a" "b"` wouldn't be so intuitively if one of them is
>> undefined then so should the other be.
>>
>> Does anyone else recall seeing a statement about output redirection to
>> an expression requiring parens and, if so, do you recall where it
>> existed?
>
> What I recall is that a few times there were discussions about that,
> but there was (AFAIR) never a formal explanation.
>
> My thoughts about your question above are as follows...
>
> getline expressions might consider precedence rules, and since in
> C-like languages (as opposed to e.g. Algol68) have the precedence
> associated with the concrete symbol ('<', '>') as opposed to the
> semantic context, so 'less than' would bind stronger than 'concat'.
> In cases where (as quoted above) "conventional parsing" deviates
> from that (whatever "conventional" or "non-conventional" will be)
> it might be different.
>
> Note also that I wrote "getline *expressions*" as opposed to, say,
> "print *statement*"; getline is part of the expression (it has a
> value) where print has an expression argument. There is (I think)
> no expression that starts with '>' in awk, so 'print >' should be
> a redirection indication, generally.
>
> Depending on semantical context an expression
>   if (getline < "a" + i) ...
> can make sense in both cases, try reading from "a" and adding a
> constant to the return value, or reading from "a1", "a42", etc.
>
> So I can see why one is undefined but not the other. And my coding
> approach would be to make the intention visible by parenthesis.
>
> Janis
>
>>
>>      Ed.
>

Good point about `if (getline < "foo")` being valid while `if (print >
"foo")` is not, thanks.

In different parts of the POSIX spec they refer to `getline` as a
"function" and an "operator" and a "keyword" (while "print" is referred
to as a "statement" and a "keyword") so it's a little hard to say
exactly what `getline` is but they do also say at one point "the
expression containing getline" so that does match your thought above
about getline being part of an expression.

Ed.

Re: Awk output redirection to expression - defined or not?

<u4vuhi$ue2g$1@dont-email.me>

  copy mid

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

  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: Re: Awk output redirection to expression - defined or not?
Date: Sun, 28 May 2023 18:12:33 +0200
Organization: A noiseless patient Spider
Lines: 34
Message-ID: <u4vuhi$ue2g$1@dont-email.me>
References: <u4nret$3gtc9$2@dont-email.me> <u4nvbq$3i31i$1@dont-email.me>
<u4vma2$svhp$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 28 May 2023 16:12:34 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="fdd4a532c31672d14773b2c7f4ee129c";
logging-data="997456"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19onz7iaqoLnsNH0MJf6Bb4"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:2sgz+vyzG6hfPcJ0p7o5pvubyZM=
In-Reply-To: <u4vma2$svhp$1@dont-email.me>
X-Enigmail-Draft-Status: N1110
 by: Janis Papanagnou - Sun, 28 May 2023 16:12 UTC

On 28.05.2023 15:52, Ed Morton wrote:
> On 5/25/2023 10:37 AM, Janis Papanagnou wrote:
>> [...]
>
> Good point about `if (getline < "foo")` being valid while `if (print >
> "foo")` is not, thanks.
>
> In different parts of the POSIX spec they refer to `getline` as a
> "function" and an "operator" and a "keyword" (while "print" is referred
> to as a "statement" and a "keyword") so it's a little hard to say
> exactly what `getline` is but they do also say at one point "the
> expression containing getline" so that does match your thought above
> about getline being part of an expression.

I haven't inspected the POSIX specs for that, but the points you
quote here are (quite) consistent and coherent.
Of course both (print/getline) can be [implemented as] "keywords"
whether they are "statements" or "functions".
The qualification [of getline] between "function" and "operator"
I consider a bit unprecise; usually I think of these as syntactic
differing forms

minus(x) vs. -x
minus(x,y) vs. x-y or even x minus y

A function and an operator can of course both be part of an
expression.

Janis

>
> Ed.
>

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor