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

acceptable signatures

Thread Next
From:
Ricardo Signes
Date:
January 29, 2014 02:58
Subject:
acceptable signatures
Message ID:
20140129025803.GA3664@cancer.codesimply.com
I've been puttering with the signatures branch, our minimum requirements, and
the question of whether we want to merge this for 5.20.0.

We are not going to merge simple signatures as they stand for 5.20.0.

I think that we're very close, though, to something that should be merged and
considered a ready experiment.  I'll try to quickly go through what behavior we
require, and will keep it brief.

In the simplest case:

  sub add ($x, $y) { say $x + $y }

  add(1,2); # "3"

The variables named in the signature are lexicals available in the body of the
subroutine.  I think everybody's been on the page with this one, and we have
that.  undef can appear in the list to drop input on the floor.  Great.

Here are further requirements not yet met:

  * all named parameters must be scalar, except for the last, which may be
    -either- hash or array
  * argument count must match up; if the caller provides too few or too many,
    it is a runtime error
  * if a subroutine is to have a prototype -and- signature, the prototype
    must be provided with the `prototype` attribute
  * each variable can be given a default expression, to be evaluated on each
    call to the sub, if the default is needed

For example:

  sub add ($x, $y=0) :prototype($$) { say $x + $y }

  my @arr = qw(2 4 6 8 9 0);
  add(@arr); ==> "6"

(I didn't take time to make this example a compelling use case, but it should
make the idea clear.)

If we can get this in line in the next few days, I am still open to declaring
it good for 5.20.0, pending code review, and I think we can be pretty flexible
on defaults.  If the only default we support is undef, out of the box, that's a
start.

Failing that, it will be merged into 5.21.x as early as possible.

-- 
rjbs

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