develooper Front page | perl.perl5.porters | Postings from October 2012

Re: sub signatures - too few arguments

Thread Previous | Thread Next
From:
Eirik Berg Hanssen
Date:
October 27, 2012 16:14
Subject:
Re: sub signatures - too few arguments
Message ID:
CAHAeAG5i36UNoB6DA1s3AtRfo8cbuZgnFnkfhirid_9Mr-_D=A@mail.gmail.com
On Sun, Oct 28, 2012 at 12:35 AM, Peter Martini <petercmartini@gmail.com>wrote:

> Or, of course, make all optional parameters part of an array, but it's
> ugly to have to do:
>
> sub foo($bar, @optional){
>    my $baz =$#optional >= 0 ? $optional[0] : 5;
>    my $quz =$#optional >= 1 ? $optional[1] : 6;
> }
>

  I'd like, à la Perl6:

sub foo ($bar, $baz=5, $qux=6) { ... }

  ... for which signature(&foo)->min == 1 and signature(&foo)->max == 3.

  (Or, if we're going to follow Perl6 nomenclature on the signature object
as well, that's signature(&foo)->arity == 1 and signature(&foo)->count ==
3, I believe.)

  Eventually.

  (I thought we were going to punt on the details of optional parameters
for now?)


Eirik

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