Method/Sub Binding In Raku

@user0721090601 already gave the answer for subs. To do the same for methods is slightly more involved. Fortunately, there is a module in the ecosystem that makes that easier for you: Method::Also. This allows you to say:

use Method::Also;
# ...
method foo() is also<bar bazzy> {

And then you can call the .bar and .bazzy methods as well, and get the same result as calling the .foo method.


Actually, what you do with normal variables is pretty much exactly what you do with subs.

sub sub1 { say "sub1!" }

my &sub2 = &sub1;

sub1; # sub1!
sub2; # sub1!

You don't need to bind, actually, because subs are not containerized and &-sigiled variables don't have special handling for assignment like @ and %-sigiled variables. (If you do a .WHICH or .WHERE you can see that they point to the same place in memory).