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:
Darren Duncan
Date:
January 20, 2022 15:53
Subject:
Re: Things you can't do in a signatured sub
Message ID:
b1a40f1f-89b2-7f3e-d012-c786d12afd4b@darrenduncan.net
On 2022-01-20 3:35 a.m., H.Merijn Brand wrote:
> With signatures and named arguments, this is much more complicated than
> the example you give:
> 
>   method foo (Int :$x, Int :$y = 42, Bool :$z = False) {
>       }
> 
>   foo (x =>  1,   z => False);
>   foo (y => 42, :$z);
> 
> You cannot use arity to check *what* named argument was passed and if
> it was assigned a default value or if the caller passed the default
> value.

And now we're on a tangent that was also important to me, which is that I feel 
support for native named parameters is important, and while current signatures 
doesn't have them.

It would be great if what becomes non-experimental with signatures now is 
something that doesn't have design decisions that would block the later addition 
of named parameters.

Named parameters are generally the most elegant way to support what would 
otherwise be alternative sets of positional parameters or optional parameters, 
and they are generally the most elegant way to design constructors or 
multi-property-setters.

-- Darren Duncan

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