Buddha Buck writes:
: So you'd have something like:
: 
: sub operator:mult($a, $b) is looser('*') is inline {...}
: sub operator:add($a, $b) is tighter("+") is inline {...}
: sub operator:div($a,$b) is looser("/") is inline {...}
: 
: assuming default Perl5 precedences for *, *, and / you would have the 
: precedence strings for *, +, /, mult, add, and div to be "S", "R", "S", 
: "S2", "S1", "S2" respectively?  So mult and div would have the same 
: precedences?

Yes.  This seems the most sensical approach to me.  If you base two
operators on the same precedence level with the same pedigree, they
should have the the same precedence.  One can always differentiate them
explicitly.  I could even see people setting up a system of "virtual"
operators that are just there for deriving precedence from, so you
could have 20 standard levels of precedence between * and + if you
wanted.

    sub operator:PREC1($a, $b) is tighter('+')     {...}
    sub operator:PREC2($a, $b) is tighter('PREC1') {...}
    sub operator:PREC3($a, $b) is tighter('PREC2') {...}
    ...

    sub operator:funky($a, $b) is like("PREC13") { ... }

: Hmmm....  What problems would be caused by:
: 
: sub operator:radd($a,$b) is tighter("+") is inline is rightassociative {...}
: sub operator:ladd($a,$b) is tighter("+") is inline is leftassociative {...}
: 
: Right now, all the operator precedence levels in Perl5 have either right, 
: left, or no associativity, but they do not mix right and left associative 
: operators.  Will that be allowed in Perl6?

Well, associativity is mostly just a tie-breaking rule, so we'd just
want to refine the tie-breaking rule to say what happens in that case.
It's possible the right thing to do is to treat conflicting associativity
as non-associative, and force parentheses.

Larry

Reply via email to