Larry (>):
[...]
The non-chaining precedence level is a bunch non-associative operators
like .. and cmp.  Historically, all operators of a particular precedence
level have had the same associativity, so that when you analyze

    $a op1 $b op2 $c

you only have to compare op1 with op2 if they're the same precedence, and
given the prededence you don't actually have to look at the individual
ops.  What would it mean to have a left-associative op at the same precedence
level as a right-associative op:

    $a lefty $b righty $c

Who would win?  So generally we try not to mix associativity within a
precedence level.

Short question: what would happen if I as the user would try and
define two operators on the same precedence level, and then try to use
them in the above way? How far would I get?

In other words, I'd do something like this:

my sub infix:<lefty>  is assoc('left')  ($a, $b) { $a - $b; }
my sub infix:<righty> is assoc('right') ($a, $b) { $a - $b; }

say (1 lefty 2 righty 3);   # a-ha! will this be -4 or 2 ?

Pugs currently dies on evaluating the last line, explaining to me that
an "ambiguous use of a right associative operator" occurred. This
might even be a fairly sane behavior. The only alternative I can think
of right now would be to disallow even _declaring_ two operators of
different associativity on the same precedence level... but that kind
of strictitude doesn't sound very perlish.

Kindly,
--
masak

Reply via email to