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

Re: arity checking (was Re: PSC #049 2022-01-07)

Thread Previous | Thread Next
From:
Yuki Kimoto
Date:
February 15, 2022 02:07
Subject:
Re: arity checking (was Re: PSC #049 2022-01-07)
Message ID:
CAExogxMB4rZVfvYPQCgyCS8-zuyJMMv_UHS9G7WkvuFQnmeVPQ@mail.gmail.com
2022-2-15 10:50 Yuki Kimoto <kimoto.yuki@gmail.com> wrote:

>
> 2022-2-15 2:12 Paul "LeoNerd" Evans <leonerd@leonerd.org.uk> wrote:
>
>>
>>   my ( $minargs, $maxargs ) = builtin::sub_arity $method;
>>   $self->die( "Too few arguments for .$d directive" )  if 1+@args <
>> $minargs;
>>   $self->die( "Too many arguments for .$d directive" ) if 1+@args >
>> $minargs;
>>
>>   return $self->$method( @args );
>>
>> Perl currently does not provide this. So I can't.
>>
>>
> If  signatures enable arity checking, there is a strong need for the API
> to get the minimum and maximum number of arguments.
>
> This is because generally speaking, module authors know the details of
> Perl language, but module users don't know the details.
>
>
Additional Description:

In this way, @_ can be suppressed because the definition of a signature is
determined at compile time;

Callbacks can receive the correct arguments.

  $cb->(splice @args, 0, $maxargs);

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