Raku/problem-solving

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

Opened this issue · 2 comments

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

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

To be more specific:

tx @raiph I will MRP this a bit and revert