I made a comment on your blog which is awaiting moderation. Anyways here it
is for people on the mailing list:
I agree that being able to compose dispatchers and candidates procedurally
is very useful. And you can sorta do it. Check out:
https://github.com/LLFourn/p6-CompUnit-Util#dispatcher-manipulation
especially this line:
https://github.com/LLFourn/p6-CompUnit-Util/blob/master/lib/CompUnit/Util.pm6#L233
where I have to create a proto. This works but there is a serialization bug
which breaks precompilation if it's done at compile time.
but doing it at runtime should work:
sub create-proto($name) {
my $proto = (my proto anon (|) {*}).clone;
$proto.set_name($name);
return $proto;
}
my $proto = create-proto('foo');
$proto.add_dispatchee(anon sub candidate1('one') { 'one' });
$proto.add_dispatchee(anon sub candidate2('two') { 'two' });
say $proto.('one');
say $proto.perl;
.say for $proto.candidates;
The above will work but it's quite fragile. Try assigning the sub to a
variable first and then .add_dispatchee (it will die). It definitely needs
a nicer interface. The design docs say that protos should have .push and
mentions that you should be able to do Proto.new.
https://design.perl6.org/S06.html#Introspection
On Mon, Feb 15, 2016 at 6:36 AM yary wrote:
> Back in June of last year some discussion about multi-subs got me
> thinking and posting about anonymous proto/multi routines here. It's
> been bubbling in the back of my mind since then, and as my Valentine
> to the language, I've posted my thoughts at
>
> http://blogs.perl.org/users/yary/2016/02/apropos-proto-perl6c-multi-thoughts.html
>
> It's a more coherent (I hope!) follow-up to
> https://www.mail-archive.com/perl6-language@perl.org/msg34937.html
>
> Would appreciate feedback on the merits or perils of exposing a way
> for creating a truly anonymous multi. It's something the design spec
> isn't explicit on.
>
> -y
>