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

Re: De-experimentalising "signatures"

Thread Previous | Thread Next
From:
Paul "LeoNerd" Evans
Date:
February 8, 2021 23:46
Subject:
Re: De-experimentalising "signatures"
Message ID:
20210208234640.1182c608@shy.leonerd.org.uk
On Mon, 8 Feb 2021 10:32:17 +0900
Yuki Kimoto <kimoto.yuki@gmail.com> wrote:

> My strong complaint about current signature is that by default there
> is a validation check of the number of arguments.
> 
> At least, I hope
> 
> sub func ($foo, $bar) {
> 
> }
> 
> is same as
> 
> sub func  {
>   my ($foo, $bar) = @_;
> }
> 
> My hope is that syntax sugar feature and type checking feature is
> separated.

Honestly, the arity checking is an often-requested feature, and one
that most signature-users find natural and welcome. In my opinion it
has always been an error that perl's regular list assignment in that
case doesn't check.

In fact, one of my possible feature ideas for "Perl in 2025" (see my
FOSDEM talk), was to consider a generic list-assignment operator that
behaves the same as signatures, precisely so you could get the benefit
of that arity checking (as well as defaults and other features). E.g.
you could

  let ($one, $two, $three = 3) = @values;

to have the same length-checking and default-assigning semantics as a
signature.

-- 
Paul "LeoNerd" Evans

leonerd@leonerd.org.uk      |  https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/  |  https://www.tindie.com/stores/leonerd/

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