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

Setting Raku custom operator precedence to feed (==>) #449

Open
librasteve opened this issue Oct 17, 2024 · 2 comments
Open

Setting Raku custom operator precedence to feed (==>) #449

librasteve opened this issue Oct 17, 2024 · 2 comments
Labels
rakudo Big changes to Rakudo

Comments

@librasteve
Copy link

Recently I tried this code as part of a blog post

use Definitely;

enum Meat <Chicken Beef Pork Fish Veggie>;

enum Ingredient <Cheese Rice Beans Salsa>;

sub returnBurrito($meat, @ingredients) {
    $meat, @ingredients
}

sub tortilla {
    returnBurrito(something(Veggie), [])
}

sub add-meat($meat, ($, @ingredients)) {
    something($meat), @ingredients
}

sub add-mission-burrito-ingredients(($meat, @ingredients)) {
    $meat, [Cheese, Rice, Beans, |@ingredients]
}

proto infix:«>>=»($ ,$) is prec(prec => ‘f=’) {*}
#proto infix:«>>=»($ ,$) is looser(&infix:<xor>) {*} #also errors

multi infix:«>>=»((None $, @), +@ ) { nothing(Meat),[] }

multi infix:«>>=»($burrito, +(&f, +@args)) {
    f( |@args, $burrito )
}

tortilla()
>>= (&add-meat, Beef)
>>= &add-mission-burrito-ingredients;

The is prec(prec => ‘f=’) trait on the proto was suggested in a comment by @wamba.

While the example above errors, applying the is prec at the candidate level DOES WORK:

multi infix:«>>=»($burrito, +(&f, +@args)) is prec(prec => 'f=') {
    f( |@args, $burrito )
}

However, comments in the SO by @raiph suggest that the use of the is prec trait is not supported:

"Setting Raku custom operator precedence to feed (==>)" First and foremost, the doc you linked says you can't do that. If you already know that, then I'm not sure what this SO is about. If you were just confused, then hopefully this makes it clearer: gist.github.com/raiph/97340c06c423b0d338a6f2542d792055 (And if it's the latter, then perhaps delete this SO question?)

Therefore, I am proposing via this Problem Solving Issue to somehow enable and support the setting of custom operator precedence equivalent to Sequencer (ie feed ==>) level.

Perhaps this can be done by simply documenting the working example I give above, perhaps the is prec trait is deprecated and due for removal, in which case a modification of the way feed operator syntax works would be needed.

A comment by @ab5stract via IRC/Discord suggests a review of precendence levels should include specifying the desired level with an enum.
https://discord.com/channels/538407879980482560/633753286209699870/1295463553918308435

@librasteve librasteve added the rakudo Big changes to Rakudo label Oct 17, 2024
@raiph
Copy link

raiph commented Oct 17, 2024

comments ... suggest that the use of the is prec trait is not supported

To be more specific:

@librasteve
Copy link
Author

librasteve commented Oct 17, 2024

tx @raiph I will MRP this a bit and revert

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rakudo Big changes to Rakudo
Projects
None yet
Development

No branches or pull requests

2 participants