Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

possible inconsistency in "perlop" documentation on precedence of || and // #15280

Closed
p5pRT opened this issue Apr 18, 2016 · 12 comments
Closed

Comments

@p5pRT
Copy link

p5pRT commented Apr 18, 2016

Migrated from rt.perl.org#127921 (status was 'resolved')

Searchable as RT127921$

@p5pRT
Copy link
Author

p5pRT commented Apr 18, 2016

From wolf-dietrich_moeller@t-online.de

Hello,
I think the following issue in the “perlop”-documentation needs clarification.

In the section on “Operator Precedence and Associativity” there is the text​:
“Operator precedence means some operators are evaluated before others. For example, in 2 + 4 * 5, the multiplication has higher precedence so 4 * 5 is evaluated first yielding 2 + 20 == 22 and not 6 * 5 == 30.”
(BTW, this text is more clarified wrt. grouping in the new proposed text in perl bug #127391).

And further below​:
“In the following *sections*, these operators are covered *in precedence order*.”

In the text further below in perlop these operators are listed in *separate* sections​:
 C-style Logical Or
 Logical Defined-Or
This means that “C-style Logical-Or” should have higher precedence than “Logical Defined-Or”.

The test program below has no grouping in line 3, but gives an explicit order of evaluation by grouping in lines 4 and 5​:


# test for precedence of || and //
my ($x,$y) = (0,1);
print $x // $y || 'last3',"\n"; # line 3
print+ ($x // $y) || 'last4',"\n"; # line 4
print $x // ($y || 'last5'),"\n"; # line 5


This program yields the output​:
Last3
Last4
0


This result shows that both operators in line 3 have the same precedence, as they are evaluated left-to-right (same as line 4). According to the perlop-documentation, line 3 should yield the same result as line 5 (higher precedence for “||”).

My suggestion is to combine the two sections on “C-style Logical-Or” and “Logical Defined-Or” in one section, as this would clearly show that both operators have the same precedence (as implemented in Perl).
(Changing the implementation of Perl to give higher precedence for “||” is probably no good idea).

I tested this issue with both Perl 5.16 and Perl 5.22, and probably it existed since the introduction of “Logical Defined-Or”.

Best regards
Wolf Moeller

@p5pRT
Copy link
Author

p5pRT commented Apr 19, 2016

From zefram@fysh.org

Wolf-Dietrich Moeller wrote​:

In the text further below in perlop these operators are listed in
*separate* sections​:
* C-style Logical Or
* Logical Defined-Or
This means that "C-style Logical-Or" should have higher precedence than
"Logical Defined-Or".

The problem, such as it is, is entirely in the documentation; we should
certainly not change the actual operator precedence.

I think "covered in precedence order" doesn't require that there be only
one section per precedence level. Two operators treated serially that
have the same precedence still qualify as being in precedence order.
But the sectioning is in fact mostly one section per precedence level,
and consistency would be worthwhile. In addition to "||" and "//",
"~~" has a separate section despite having the same precedence as "=="
and other operators.

-zefram

@p5pRT
Copy link
Author

p5pRT commented Apr 19, 2016

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Apr 20, 2016

From @Smylers

Wolf-Dietrich Moeller writes​:

I think the following issue in the “perlop”-documentation needs
clarification.

In the section on “Operator Precedence and Associativity” there is the
text​:
“Operator precedence means some operators are evaluated before others.
For example, in 2 + 4 * 5, the multiplication has higher precedence so
4 * 5 is evaluated first yielding 2 + 20 == 22 and not 6 * 5 == 30.”

And further below​:
“In the following *sections*, these operators are covered *in
precedence order*.”

However, in-between those two parts you quoted there is also​:

  Perl operators have the following associativity and precedence, listed
  from highest precedence to lowest.

followed by a table, which includes these lines​:

  nonassoc == != <=> eq ne cmp ~~
  ⋮
  left || //

That clearly asserts that it specifies precedence levels, and shows that
|| and // (and == and ~~) are of equivalent precedence.

In the text further below in perlop these operators are listed in
*separate* sections​:
 C-style Logical Or
 Logical Defined-Or
This means that “C-style Logical-Or” should have higher precedence
than “Logical Defined-Or”.

The precedence is specified, correctly, in the table you skipped over.
The sentence “In the following sections, these operators are covered in
precedence order” is a description about the documentation that follows,
not about precedence in Perl — it's informing readers how to navigate
the subsequent sections, given the precedence order that's already been
defined above it.

Zefram writes​:

I think "covered in precedence order" doesn't require that there be
only one section per precedence level.

Quite.

But the sectioning is in fact mostly one section per precedence level,
and consistency would be worthwhile. In addition to "||" and "//",
"~~" has a separate section despite having the same precedence as "=="
and other operators.

I think merging into a single sections could make reading and navigating
them harder. The ~~ and // sections are both quite long compared with
their preceding sections.

If somebody wants a definition of eq or ||, they can currently be sure
they've read all their is to know about it in a relatively short
section. Bloating those with the more niche definitions of ~~ and //
would substantially increase the reading time for those sections, even
for people who don't need to know about those specific operators.

Smylers
--
http​://twitter.com/Smylers2

@p5pRT
Copy link
Author

p5pRT commented Apr 25, 2016

From wolf-dietrich_moeller@t-online.de

Smylers writes​:

However, in-between those two parts you quoted there is also​:

Perl operators have the following associativity and precedence, listed
from highest precedence to lowest.

followed by a table, which includes these lines​:

 nonassoc    == \!= \<=> eq ne cmp ~~
 ⋮
 left        || //

That clearly asserts that it specifies precedence levels, and shows that
|| and // (and == and ~~) are of equivalent precedence.
...
The precedence is specified, correctly, in the table you skipped over.
The sentence “In the following sections, these operators are covered in
precedence order” is a description about the documentation that follows,
not about precedence in Perl — it's informing readers how to navigate
the subsequent sections, given the precedence order that's already been
defined above it.

These two sentences you cite are quite similar wrt expression and grammar, but you write that these sentence should *not* be interpreted in the same way. You say that the first sentence *specifies* an ordering line by line. But why is the second sentence to be interpreted in a more fuzzy way, while it has similar wording and grammar?
For me these similar sentences indicate that either both operator list and sections below or none of them are exactly ordered. I cannot follow you to see the difference you describe from the wording of the sentences.

So either these two sentences should be clarified, or both operator list and sections below should obey the *same* ordering rules.

BTW, Smylers also writes​:

If somebody wants a definition of eq or ||, they can currently be sure
they've read all their is to know about it in a relatively short
section.
This is not true as the section on || is not complete. While the first paragraph of the section on // is in fact about //, the following paragraphs in the section on // are about the three operators &&, || and //. Thus people looking for || (or &&) will even miss these helpful explanations, if they only read the sections on || or &&.
In addition, this could even lead to the (wrong) impression, that all three operators have the same precedence, as they are covered together in this section.
Maybe it would be worthwhile to do an overhaul to that part also (it seems to me that the section on // was added to the doc at a later stage, and unfortunately not really consistent).

Taking this together, it may be best to delete the reference to "precedence order" for the sections, and change the sentence below the operator list to something like "In the following sections, these operators are covered *in detail*." This would avoid wrong conclusions about precedence derived from the section list.

Wolf

@p5pRT
Copy link
Author

p5pRT commented Jun 20, 2016

From @iabyn

On Mon, Apr 25, 2016 at 06​:37​:36PM +0200, Wolf-Dietrich Moeller (München) wrote​:

Smylers writes​:

However, in-between those two parts you quoted there is also​:

Perl operators have the following associativity and precedence, listed
from highest precedence to lowest.

followed by a table, which includes these lines​:

 nonassoc    == \!= \<=> eq ne cmp ~~
 ⋮
 left        || //

That clearly asserts that it specifies precedence levels, and shows that
|| and // (and == and ~~) are of equivalent precedence.
...
The precedence is specified, correctly, in the table you skipped over.
The sentence “In the following sections, these operators are covered in
precedence order” is a description about the documentation that follows,
not about precedence in Perl — it's informing readers how to navigate
the subsequent sections, given the precedence order that's already been
defined above it.

These two sentences you cite are quite similar wrt expression and grammar, but you write that these sentence should *not* be interpreted in the same way. You say that the first sentence *specifies* an ordering line by line. But why is the second sentence to be interpreted in a more fuzzy way, while it has similar wording and grammar?
For me these similar sentences indicate that either both operator list and sections below or none of them are exactly ordered. I cannot follow you to see the difference you describe from the wording of the sentences.

So either these two sentences should be clarified, or both operator list and sections below should obey the *same* ordering rules.

BTW, Smylers also writes​:

If somebody wants a definition of eq or ||, they can currently be sure
they've read all their is to know about it in a relatively short
section.
This is not true as the section on || is not complete. While the first paragraph of the section on // is in fact about //, the following paragraphs in the section on // are about the three operators &&, || and //. Thus people looking for || (or &&) will even miss these helpful explanations, if they only read the sections on || or &&.
In addition, this could even lead to the (wrong) impression, that all three operators have the same precedence, as they are covered together in this section.
Maybe it would be worthwhile to do an overhaul to that part also (it seems to me that the section on // was added to the doc at a later stage, and unfortunately not really consistent).

Taking this together, it may be best to delete the reference to "precedence order" for the sections, and change the sentence below the operator list to something like "In the following sections, these operators are covered *in detail*." This would avoid wrong conclusions about precedence derived from the section list.

If no-one objects, I'll apply the following in a few days' time​:

-In the following sections, these operators are covered in precedence order.
+In the following sections, these operators are covered in detail, in the
+same order in which they appear in the table above.

--
You live and learn (although usually you just live).

@p5pRT
Copy link
Author

p5pRT commented Jun 20, 2016

From @khwilliamson

On 06/20/2016 06​:46 AM, Dave Mitchell wrote​:

On Mon, Apr 25, 2016 at 06​:37​:36PM +0200, Wolf-Dietrich Moeller (München) wrote​:

Smylers writes​:

However, in-between those two parts you quoted there is also​:

Perl operators have the following associativity and precedence, listed
from highest precedence to lowest.

followed by a table, which includes these lines​:

  nonassoc    == \!= \<=> eq ne cmp ~~
  ⋮
  left        || //

That clearly asserts that it specifies precedence levels, and shows that
|| and // (and == and ~~) are of equivalent precedence.
...
The precedence is specified, correctly, in the table you skipped over.
The sentence “In the following sections, these operators are covered in
precedence order” is a description about the documentation that follows,
not about precedence in Perl — it's informing readers how to navigate
the subsequent sections, given the precedence order that's already been
defined above it.

These two sentences you cite are quite similar wrt expression and grammar, but you write that these sentence should *not* be interpreted in the same way. You say that the first sentence *specifies* an ordering line by line. But why is the second sentence to be interpreted in a more fuzzy way, while it has similar wording and grammar?
For me these similar sentences indicate that either both operator list and sections below or none of them are exactly ordered. I cannot follow you to see the difference you describe from the wording of the sentences.

So either these two sentences should be clarified, or both operator list and sections below should obey the *same* ordering rules.

BTW, Smylers also writes​:

If somebody wants a definition of eq or ||, they can currently be sure
they've read all their is to know about it in a relatively short
section.
This is not true as the section on || is not complete. While the first paragraph of the section on // is in fact about //, the following paragraphs in the section on // are about the three operators &&, || and //. Thus people looking for || (or &&) will even miss these helpful explanations, if they only read the sections on || or &&.
In addition, this could even lead to the (wrong) impression, that all three operators have the same precedence, as they are covered together in this section.
Maybe it would be worthwhile to do an overhaul to that part also (it seems to me that the section on // was added to the doc at a later stage, and unfortunately not really consistent).

Taking this together, it may be best to delete the reference to "precedence order" for the sections, and change the sentence below the operator list to something like "In the following sections, these operators are covered *in detail*." This would avoid wrong conclusions about precedence derived from the section list.

If no-one objects, I'll apply the following in a few days' time​:

-In the following sections, these operators are covered in precedence order.
+In the following sections, these operators are covered in detail, in the
+same order in which they appear in the table above.

+1

@p5pRT
Copy link
Author

p5pRT commented Jun 21, 2016

From @xsawyerx

On 06/20/2016 02​:46 PM, Dave Mitchell wrote​:

On Mon, Apr 25, 2016 at 06​:37​:36PM +0200, Wolf-Dietrich Moeller (München) wrote​:

Smylers writes​:

However, in-between those two parts you quoted there is also​:
Perl operators have the following associativity and precedence, listed
from highest precedence to lowest.

followed by a table, which includes these lines​:

 nonassoc    == \!= \<=> eq ne cmp ~~
 ⋮
 left        || //

That clearly asserts that it specifies precedence levels, and shows that
|| and // (and == and ~~) are of equivalent precedence.
...
The precedence is specified, correctly, in the table you skipped over.
The sentence “In the following sections, these operators are covered in
precedence order” is a description about the documentation that follows,
not about precedence in Perl — it's informing readers how to navigate
the subsequent sections, given the precedence order that's already been
defined above it.
These two sentences you cite are quite similar wrt expression and grammar, but you write that these sentence should *not* be interpreted in the same way. You say that the first sentence *specifies* an ordering line by line. But why is the second sentence to be interpreted in a more fuzzy way, while it has similar wording and grammar?
For me these similar sentences indicate that either both operator list and sections below or none of them are exactly ordered. I cannot follow you to see the difference you describe from the wording of the sentences.

So either these two sentences should be clarified, or both operator list and sections below should obey the *same* ordering rules.

BTW, Smylers also writes​:

If somebody wants a definition of eq or ||, they can currently be sure
they've read all their is to know about it in a relatively short
section.
This is not true as the section on || is not complete. While the first paragraph of the section on // is in fact about //, the following paragraphs in the section on // are about the three operators &&, || and //. Thus people looking for || (or &&) will even miss these helpful explanations, if they only read the sections on || or &&.
In addition, this could even lead to the (wrong) impression, that all three operators have the same precedence, as they are covered together in this section.
Maybe it would be worthwhile to do an overhaul to that part also (it seems to me that the section on // was added to the doc at a later stage, and unfortunately not really consistent).

Taking this together, it may be best to delete the reference to "precedence order" for the sections, and change the sentence below the operator list to something like "In the following sections, these operators are covered *in detail*." This would avoid wrong conclusions about precedence derived from the section list.
If no-one objects, I'll apply the following in a few days' time​:

-In the following sections, these operators are covered in precedence order.
+In the following sections, these operators are covered in detail, in the
+same order in which they appear in the table above.

+1.

@p5pRT
Copy link
Author

p5pRT commented Jul 18, 2016

From @iabyn

On Mon, Jun 20, 2016 at 01​:46​:14PM +0100, Dave Mitchell wrote​:

If no-one objects, I'll apply the following in a few days' time​:

-In the following sections, these operators are covered in precedence order.
+In the following sections, these operators are covered in detail, in the
+same order in which they appear in the table above.

Now done with v5.25.2-194-g3df91f1.

--
This email is confidential, and now that you have read it you are legally
obliged to shoot yourself. Or shoot a lawyer, if you prefer. If you have
received this email in error, place it in its original wrapping and return
for a full refund. By opening this email, you accept that Elvis lives.

@p5pRT
Copy link
Author

p5pRT commented Jul 18, 2016

@iabyn - Status changed from 'open' to 'pending release'

@p5pRT
Copy link
Author

p5pRT commented May 30, 2017

From @khwilliamson

Thank you for filing this report. You have helped make Perl better.

With the release today of Perl 5.26.0, this and 210 other issues have been
resolved.

Perl 5.26.0 may be downloaded via​:
https://metacpan.org/release/XSAWYERX/perl-5.26.0

If you find that the problem persists, feel free to reopen this ticket.

@p5pRT p5pRT closed this as completed May 30, 2017
@p5pRT
Copy link
Author

p5pRT commented May 30, 2017

@khwilliamson - Status changed from 'pending release' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant