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

Re: Proposal: Named parameters for 5.12

Thread Previous | Thread Next
From:
Michael G Schwern
Date:
February 21, 2009 22:43
Subject:
Re: Proposal: Named parameters for 5.12
Message ID:
49A0F401.8010005@pobox.com
Chip Salzenberg wrote:
> What say we make named parameters part of Perl 5.12?  (Finally?!)
> 
> A quick check of CPAN suggests that Schwern's code in Method::Signature
> defines the state of this particular art.  I think we could make a less
> seam-y approach in the core, but the feature set looks really good;
> 
>     http://search.cpan.org/~mschwern/Method-Signatures-20081028/lib/Method/Signatures.pm
> 
> Meanwhile, some older stuff for comparison includes:
> 
>     http://search.cpan.org/~flora/signatures-0.02/lib/signatures.pm
>     http://search.cpan.org/~chips/Perl6-Subs-0.05/lib/Perl6/Subs.pm

Sorry to resurrect this thread, I'm catching up on p5p.  I'm very happy Chip
brought it up.  I really want to see this happen.  Here's a sum up.

There's a bunch of modules that are moving in the same direction wrt adding
proper signatures to Perl 5.  rafl, Rhesa and myself kibitzed about the syntax
pretty intensely last fall, backed by Matt Trout.  They have different
purposes.  signatures.pm and Method::Signatures::Simple have stripped down
syntaxes to simplify their implementations and extra stuff having to do with
writing your own syntax.  The two most interesting for the purposes of being
language prototypes (as opposed to production use) are these
Method::Signatures and MooseX::Method::Signatures.

They both start with Perl 6's signature syntax, but then bend them to fit in
Perl 5.  Why?  Some things which make sense in Perl 6 don't make any sense in
Perl 5.  Perl 5 is also missing some key concepts and syntax.  And while it's
nice to be upward compatible with Perl 6, it shouldn't be at the expense of
hobbling the feature in Perl 5.

Method::Signatures explains the differences in detail and the reasons why:
http://search.cpan.org/perldoc?Method::Signatures#Differences_from_Perl_6

Method::Signatures implements a "method" keyword, named parameters, aliased
references, invocants, defaults, parameter traits, optional parameters and
required parameters.  It does this while preserving @_ and keeping open some
room in the syntax for more extensions.

MooseX::Method::Signatures implements much of the above, but in addition it
includes type checking, constraints and labels.

Both syntaxes can be applied to normal subroutines, just remove the invocant
syntax.

Neither of them say anything about the return value.

How it is implemented does not matter.  5.12 would not use these modules.  The
important thing is having a working prototype for the syntax to put into the core.

A join of Method::Signatures and MooseX::Method::Sigantures would be what I
would recommend, minus the type checks.  Adding types to Perl 5 is an
orthogonal consideration (please argue it in another thread).

While this might not be the 100% complete signature implementation to wind up
in 5.12, there's probably plenty more to steal from Perl 6 that I'm
forgetting, it's certainly a rocket-powered head start.

With the syntax prototyped and documentation and tests written what we have
here is a Simple Matter Of Programming, for certain values of "simple" which
means "core hacking".  If there's a core hacker who wants to make this happen,
I'll be more than happy to help.


-- 
You are wicked and wrong to have broken inside and peeked at the
implementation and then relied upon it.
	-- tchrist in <31832.969261130@chthon>

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