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

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

Thread Previous | Thread Next
H.Merijn Brand
January 20, 2022 11:35
Re: Things you can't do in a signatured sub
Message ID:
On Wed, 19 Jan 2022 17:59:41 +0000, "Paul \"LeoNerd\" Evans" <> wrote:

>   * As a variant of the above; you can't even see the count of passed
>     arguments in order to distinguish no-argument from being explicitly
>     passed undef (or whatever the param default is)
>       sub not_signatured {
>         my ($x) = @_;
>         warn "X was " ? (@_ ? "the value $x" : "not passed");
>         }
>       sub signatured ($x = undef) {
>         # impossible to distinguish signatured () from signatured (undef)
>         }

FWIW: this is also impossible in raku. I have requested a feature to
detect this, but it was declined then (years ago) because it was
blocking possible optimizations in "hiding" the argument hash.

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

H.Merijn Brand   Perl Monger
using perl5.00307 .. 5.33        porting perl5 on HP-UX, AIX, and Linux

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About