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

RFC: Adding a prototype attribute

Thread Next
From:
Peter Martini
Date:
December 14, 2012 23:19
Subject:
RFC: Adding a prototype attribute
Message ID:
CAFyW6MT2gV-7-rTt808ZkY0a2fyH8y1iz1eNAPW9H13u7yQRSA@mail.gmail.com
I'd like to propose adding a prototype attribute to core.

My reasoning:

1. The current sub foo($$){} prototype binds somewhat late; the
prototype isn't attached to the sub until after the sub is completely
defined.  That's not really changeable at this point, but a prototype
attribute could have different semantics.
2. There a number of modules out there which use the syntactical space
for other purposes; adding a prototype attribute allows modules like
that to use the sub keyword and traditional prototypes at the same
time in a clean manner.
3. Lowercase attribute names are reserved for the core.

Implementation notes:

1. It would be an error to use the prototype attribute at the same
time as a prototype - meaning sub foo($$) : prototype($$) would be
illegal.  sub foo($$); sub foo : prototype($$) however would be fine.
2. Recursive use of the sub would use the prototype defined by the
attribute (not the case now, unless the prototype is pre-declared).
3. The goal of making it apply the prototype before the body of the
sub compiles rules out using the perl level attributes handlers, as
those get evaluated at the same time as the prototype is currently
added.

Any recommendations / objections?

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