This and other RFCs are available on the web at
  http://dev.perl.org/rfc/

=head1 TITLE

first class interface definitions

=head1 VERSION

  Maintainer: David Nicol <[EMAIL PROTECTED]>
  Date: 8 Aug 2000
  Version: 1
  Mailing List: [EMAIL PROTECTED]
  Number: 75

=head1 ABSTRACT


The appearance in perl6 of a structure definition as a first class object,
similar to the compiled regular expression in perl5, will ease the
implementation of a variety of complex endeavors.  This document
examines some possiblities for using it for subroutine prototyping
with named parameters.


=head1 SUMMARY


        $xys = qs{ $x, my $y }; # $x is pass by reference, $y by value

        sub foo($xys){
                print "x is $x and y is $y\n";
        };

        %fasthash = unpack( $xys, $Structure );

        $Structure = pack( $xys, %fasthash );


=head1 DESCRIPTION

Pseudohash type definitions  are Structure-Definitions are Interfaces.  All of
these may be considered key-value associative arrays.

Structure definitions are declared using the C<qs> operator,
or can be inlined in situations that syntacticly call for them,
such as function prototypes.

In invoking a subroutine prototyped using a structure definition,
(aka fully defined interface) the arguments can come from
a list, in which case they are loaded into the structure in order,
they can come from a(nother) (pseudo)hash, in which case they are
loaded into the structure by name.


rather than Special-casing the interpretation of
function call parameters, we can create an object of type $xy
and send it to the function that takes that type. This way
the name localization is in the called subroutine, and we
don't have names from subroutines appearing in the calling
code.

Any subroutine with a prototype with named variables, no matter how scoped,
can be called with a hash or hash-like structure with the
required keys, and the correct keys will be used as the subroutine
parameters.




=head1 IMPLEMENTATION

The default subroutine interface becomes C<qs{@}> like it
has been all along, but by using explicit interfaces we
can introduce a more extensive conversion step when required.

This system was proposed within RFC 61 as an implementation detail,
and after reading RFC 57 it became clear that the problems of stuffing
a set of data into the interface for an external function apply equally
to a native perl function.

I think that after settling on an extensible interface declaration
system, much cool stuff that cannot happen with the current lists
will be possible.

=head2 backward compat.

perl5 prototype definition language will be one type recognized
by C<qs>, and perl6 argument coercion will be a proper superset
of perl5 argument coercion.

subroutines expecting hashes decomposed into arrays wouldn't
have a prototype indicating anything else, so that's what they'd
get.


=head1 REFERENCES

http://dev.perl.org/rfc/57.pod
http://dev.perl.org/rfc/61.pod


Reply via email to