But that is clearly not so - *including* the parentheses in the above script alters the output (and restores commutativity):
Of course it alters the output. You are allowed to use predeclared subroutines without parenthesis, but the docs don't say that you always get the same result as with parens -- in the case without parens, you need to be aware of the precedence of your expressions.
In particular non_commutative + 10 parses as non_commutative( +10 ). You meant non_commutative() + 10, but perl can't know that; you'd have to write (non_commutative) + 10 to disambiguate.
In case you wonder what the *10 is: as a term that's the glob syntax that you might know from *STDOUT.
The precedence of subroutines without parenthesis is described in perlop as "list operators (rightward)", and looser than + and *.
Another option is to declare the sub with a prototoype:
sub non_commutative() { 17 }
Which is described in perlsub.
In reply to Re: Perl disproves commutativity of Addition/Multiplication
by moritz
in thread Perl disproves commutativity of Addition/Multiplication
by syphilis
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |