develooper Front page | perl.perl5.porters | Postings from January 2022

Re: Things you can't do in a signatured sub

Thread Previous | Thread Next
From:
Ovid via perl5-porters
Date:
January 24, 2022 20:09
Subject:
Re: Things you can't do in a signatured sub
Message ID:
290407153.945451.1643054964588@mail.yahoo.com
On Monday, 24 January 2022, 20:22:52 CET, Paul "LeoNerd" Evans <leonerd@leonerd.org.uk> wrote:

> You mean like
>
>   use v5.26;
>   use Syntax::Keyword::MultiSub;
>   use experimental 'signatures';
> 
>   multi sub max()          { return undef; }
>   multi sub max($x)        { return $x; }
>   multi sub max($x, @more) { my $y = max(@more);
>                             return $x > $y ? $x : $y; }
> 
>   -- https://metacpan.org/pod/Syntax::Keyword::MultiSub
> 
> Doesn't yet support `multi method ...` but I keep meaning to get around
> to starting implementing that.
> 
> > No, I'm not suggesting we do that, 
> 
> Oh, I am ;)

What do we do with this?

    sub max :multi(@args) {...}
    sub max :multi(%args) {...}

Because arrays and hashes flatten into a list, unless @args has an odd number of elements, we can't disambiguate them, can we?

Java also has ambiguous cases which fail, but always at compile-time. I don't think we can do that, but I would be delighted to be wrong.

Best,
Ovid
-- 
IT consulting, training, specializing in Perl, databases, and agile development
http://www.allaroundtheworld.fr/. 

Buy my book! - http://bit.ly/beginning_perl


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About