sub infix:<foo> ($a, $b = ($a foo 2 * 3 - $a)) is tighter(&infix:<*>)
{
        $a == 0 ?? 1 foo 2 * 3 !! $a + $b
}

say 1 foo (2 * 3);
# 7
say (1 foo 2) * 3;
# 9

say 1 foo 2 * 3;
# 9

say infix:<foo>(1);
# Niecza: 7

say 0 foo 0;
# Niecza: 9

The way that Niecza does this is to install the operator with default precedence
before the signature (which means the default is parsed with * binding
tighter than
foo) and then twiddling the precedence before the body (which means the $a == 0
case is parsed with foo binding tighter than *)

Is this right?
Is it necessary (i.e. does the spec mandate the operator existing
while parsing the
signature and/or body)?

I'm considering doing the work to get Rakudo to do the tighter/looser
traits and can't
find the bits of the spec which might apply to these (admittedly
bizarre) edge cases.

I suppose for completeness I should have added in some more traits
which used foo
in an expression - or is that definitely not ok?

Reply via email to