On Fri, Dec 23, 2011 at 10:59:58PM +1100, Kris Shannon wrote:
> 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 seem to recall that there was some spectest or another which required the
operator to exist in the signature.  The test wasn't using precedence, but
at the time the signature is parsed, Niecza can't know that.

It is most definitely required in the body; normal subs can be recursive, and
recursive operators like ! are a common example.

> 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.

Another even more bizarre edge case in niecza is that you can use "also"
to change the precedence of an operator in the middle of the body.

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

I can't see why it should't be ok.

-Stefan

Attachment: signature.asc
Description: Digital signature

Reply via email to