develooper Front page | perl.perl6.language | Postings from June 2005

AUTOLOAD, this time distinct from AUTOSUB etc (and spelt correctly)

Thread Next
Sam Vilain
June 20, 2005 19:03
AUTOLOAD, this time distinct from AUTOSUB etc (and spelt correctly)
Message ID:
OK, that last discussion was productive, but I think we all (including
myself) overlooked the fact that the AUTOLOAD and AUTOSUB methods are
implied to have different calling conventions;

   There is still an AUTOLOAD hook that behaves as in Perl 5.

   The (AUTO*) routines are expected to return a reference to
   an object of the proper sort (i.e. a variable, subroutine,
   or method reference), or undef if that name is not to be
   considered declared.

So, here are the prototypes of the (new) AUTO* methods:

   subtype Symbol of Str;

   sub AUTOSCALAR( Symbol $sym ) returns Ref of Scalar;
   sub AUTOARRAY ( Symbol $sym ) returns Ref of Array;
   sub AUTOHASH  ( Symbol $sym ) returns Ref of Hash;
   sub AUTOSUB   ( Symbol $sym ) returns Code;
   sub AUTOMETH  ( ::$type: Symbol $sym ) returns Code(::$type: *);

uh-oh, another sticky one; the implication is that AUTOMETH has an
invocant, which is either a Type or the object, and is expected to
return a sub whose signatute has the right type, but we don't care
to type check anything more than the invocant type.  And that's even
before we look at MMD, so for now we'll think of it as;

   sub AUTOMETH  ( Symbol $sym ) returns Ref of Code;

So, those are all well and good.  They can still do anything,
including return little micro-subs that perform arbitrary munging
of the argument stack before passing them on, or define the
sub/variable that was referred to, to avoid the AUTOFOO call the
next time around.  And they're being invoked at compile time so that
we can get their signatures, but that isn't a problem with people
doing selective loading because they're clever enough to know what
to do.  Great, we can all start using those.

But what about AUTOLOAD?  It has to "behave as in Perl 5", which had
different calling conventions and expected you to make the loaded
function call yourself.

This has some side-implications; the signature used for a Class'
AUTOLOAD will be used as the signature for all unknown function calls;
so, defining;

  sub AUTOLOAD {

Will forfeit your right to apply signatures to the arguments of an
auto-loaded method, which is probably an acceptable penalty for someone
who is just expecting P6 to work like P5 did.  Method calls, too.

It seems these requirements are still in conflict;

    - Preserving AUTOLOAD thou-shalt-make-the-call semantics
    - Keeping the new $AUTOLOAD off the argument stack for AUTOLOAD()
    - Use of $_ as an out-of-band way of passing arguments to a function
      cannot be localised due to the non-stack-like characteristic of
      the call stack, in the face of continuations and coroutines
    - disallowing "explicit" out-of-band arguments

Time to re-think the out-of-band arguments idea?


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About