Re: Anonymous multi-subs

[email protected] (Brent Laabs)
Newsgroups perl.perl6.language
Message-ID <CAAPDpBxnRkEEfLU=bTC2z+hnUzGrdmmpPCz2n7sgP-rKo-4uXQ@mail.gmail.com>
I'll just note that you can fake anon multi subs with lexical subs like
this:

my $sub = do {
    proto foo (|) { * }
    multi foo (Int $x) { $x + 1 }
    multi foo (Str $y) { $y ~ 'a' }

    &foo;
}

say $sub("hello");

The sub there is still named "foo" as attested by $sub.name, but isn't
available under that name outside of the do block.


On Wed, Jun 24, 2015 at 2:27 PM, Jon Lang <[email protected]> wrote:

>
>
> On Wednesday, June 24, 2015, yary <[email protected]> wrote:
>
>> Now that I've thought about it for 90 seconds (not fully-formed idea), if
>> one were to have an anonymous multi-sub, it ought to be constructed from a
>> list of *signature*, *body *pairs.
>>
>> And/or, any non-finalized sub could have a method to add another *signature,
>> body* to its dispatch list.
>>
>> apologies if this discussion is already captured in a design doc, I am
>> posting this without having read much of the past.
>>
>
>  Or, in the body, be able to examine the actual signature passed in and
> decide what to do based on that,  That [i]could[/i] be done using a
> given/when structure, which would be equivalent to a list of signature/body
> pairs.
>
>
> --
> Jonathan "Dataweaver" Lang
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.