[% setvar title Make subroutines' prototypes accessible from Perl %]

This file is part of the Perl 6 Archive

Note: these documents may be out of date. Do not use as reference!

To see what is currently happening visit http://www.perl6.org/


Make subroutines' prototypes accessible from Perl


  Maintainer: Simon Cozens <simon@brecon.co.uk>
  Date: 25 Sep 2000
  Mailing List: perl6-language-subs@perl.org
  Number: 298
  Version: 1
  Status: Developing


Allow sub prototypes to be got and set by Perl at compile time.


The motivation behind this RFC is to allow subroutine attributes to define canned "prototype classes". As a very trivial example:

    use attributes::prototype 'a_and_b' => "($a,$b)"

    sub foo : a_and_b { 
        # $a and $b are here set to what we knew as $_[0] and $_[1]

Now, yes, I am suggesting that there be a attributes::prototype pragma, but that's not the thrust of my RFC - the point is how you implement it, and you have to do this by making the prototype available.

That's the motivation; the justification is slightly different, and it's to increase the flexibility and the possibilities for introspection that Perl 6's subroutines provide the user. More flexibility is always a good thing.


There are a number of ways that this can be done; I'd originally thought that there should be Yet Another Special Variable, but it seems more Perlish to change prototype to be a function which returns the prototype of a built-in (same as Perl 5) or, when passed a fully qualified sub name, an lvaluable subroutine to get or set the prototype of that sub.

So attributes::prototype can then be implemented something vaguely like this: store "prototype class" declarations in a hash, say, %PROTOS; register the new attributes; when the attribute is processed, set prototype($sub) = $PROTOS{$attr}.


RFC 57: Subroutine prototypes and parameters