develooper Front page | perl.perl5.porters | Postings from April 2016

Re: [perl #127921] possible inconsistency in "perlop" documentationon precedence of || and //

Thread Previous | Thread Next
April 20, 2016 08:46
Re: [perl #127921] possible inconsistency in "perlop" documentationon precedence of || and //
Message ID:
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.


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


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About