Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

builtin operators should be referenceable #2220

Open
lichtkind opened this issue Aug 16, 2018 · 6 comments

Comments

Projects
None yet
3 participants
@lichtkind
Copy link

commented Aug 16, 2018

The Problem

The postfix<.> op is not accessible in precedence comparison.

Expected Behavior

My selfmade op MM has to be tighter than .method so i don't have to use braces to use a method on matrix created with MM

multi sub prefix: < MM > (Str $m --> ::?CLASS:D) is tighter(&postfix:<.>) is export(:MM) { ... }

Actual Behavior

that code gives error as if the operator is not there.

Undeclared routine: ....

Environment

current Perl 6.c

@zoffixznet

This comment has been minimized.

Copy link
Contributor

commented Aug 16, 2018

That looks correct to me. There isn't any posfix:<.> operator in core.

In other words, $foo.uc, $foo».uc,. $foo.?uc, $foo.*uc and all the rest of them aren't postfix operators. They're just syntax.

@lichtkind

This comment has been minimized.

Copy link
Author

commented Aug 16, 2018

i just added space to the perl 6 example code so an important part do not get invisible

@zoffixznet

This comment has been minimized.

Copy link
Contributor

commented Aug 16, 2018

I filed a docs Issue: perl6/doc#2267

You can achieve what you're looking for by using prec and setting precedence to z (not quite sure doing it this way is language-defined behaviour though):

$ perl6 -e 'sub prefix:<♥> ($) is prec({prec => "z"}) { "b" }; say ♥"a".uc'
B
@lichtkind

This comment has been minimized.

Copy link
Author

commented Aug 16, 2018

im not that comfortable with this, since reason why larry invented the is looser|tighter|equal .. is to prevent magic constants. (so core changes do not break modules)

@zoffixznet

This comment has been minimized.

Copy link
Contributor

commented Aug 16, 2018

Actually, you can set tighter than &postcircumfix:<[ ]>, since it's on the same precedence level as methodops:

$ perl6 -e 'sub prefix:<♥> ($) is tighter(&postcircumfix:<[ ]>) { "b" }; say ♥"a".uc'
B

This whole area with precedence/associativity on ops is a bit of a rough patch. Just checked now and is prec isn't even in the spec. There are also numerious tickets for is assoc and related traits, including the fact that is tighter/looser/eqv modify associativity too.

@lichtkind

This comment has been minimized.

Copy link
Author

commented Aug 16, 2018

thank YOU very much that worked

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.