Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: Precedence design question...'x' & arith

by eyepopslikeamosquito (Chancellor)
on Jul 06, 2013 at 08:16 UTC ( #1042870=note: print w/replies, xml ) Need Help??

in reply to Precedence design question...'x' & arith

While I agree with your arguments that the current Perl 5 operator precedence could be improved, I don't feel it is appropriate to change operator precedence in a language as mature as Perl 5, with millions of lines of code in production use. That is, the (small) gain of your proposed change is not worth the considerable pain.

A new language, like Perl 6, is another matter. And I see that the Perl 6 folks agree with you; that is, Perl 6 is already using your proposed operator precedence for its Replication (x and xx) and Concatenation ~ operators.

By the way, notice that the current Perl 5 string multiply precedence is the same as Ruby and Python because they both use * as the string multiply operator. Ditto for string concatenation because Ruby and Python both use the + operator for that.

Though string multiply may be rarely used in general Perl coding, it is heavily used in golf ... so your proposed precedence change would certainly be welcomed by golfers. :) To illustrate, in The golf course looks great, my swing feels good, I like my chances (Part VI), a very rare example of Python out-golfing Perl and Ruby was given:

$"x(318%$_/9) Perl " "*(318%i/9) Ruby 318%i/9*" " Python
Python was shortest here because the string multiply operator is commutative in Python (only), allowing the parentheses to be removed. That said, the most common use of string multiply in golf is with a boolean expression, for example:
"Zaphod Beeblebrox"x($n!=42)
and your proposed precedence change wouldn't help there.

Replies are listed 'Best First'.
Re^2: Precedence design question...'x' & arith
by perl-diddler (Hermit) on Jul 08, 2013 at 17:37 UTC
    Perl6 is compatible with perl5?

    What I am suggesting is.

    This is a statement that so many people don't get -- Programs cannot be *relying* on getting an error for wrong usage in a production program, as errors wouldn't deliberately be in the end program. I'm taking a case that people can't use and suggesting that a bit of extra clarity in precedence would create a more useful language without taking away usable features or causing incompatible change.

    Nothing would help in your last example as it isn't intended to mean anything.

    And if you altered the precedence in the manner I proposed, the golf course example would be:

    ' 'x318%i/9
    as the integer ops are done first.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1042870]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (10)
As of 2018-04-23 14:21 GMT
Find Nodes?
    Voting Booth?