Proposal about the "self" keyword
Allison Randal
allison at parrot.org
Sat Feb 14 21:21:29 UTC 2009
Andrew Whitworth wrote:
>
> My proposal is this: All subs get the "self" keyword, whether they
> want it or not. "self" in all subs point to the object that was being
> invoked. In an ordinary subroutine, "self" will refer to the Sub PMC
> itself. Ignore it if you don't want it, and nothing really changes
> from how things are treated now. Objects, when invoked, will have this
> "self" if they want it, which they probably always do. This also is
> going to help us a lot internally, where we can unify the functions
> for calling methods and functions for calling non-method subs. We
> simplify a few things in IMCC too, although we do pay because an extra
> parameter is being passed in many cases where it's not needed. As part
> of this, I may also like to change VTABLE_invoke to take 4 parameters
> instead of 3 (adding an optional invocant PMC, if it's different from
> the sub object being invoked).
>
> What do people think of this proposal? Any immediate problems come to
> mind that would make this a Bad Idea?
The problem is that this introduces confusion between the invocant and
the invoked code object. "self" should always and only refer to the
invocant, and never refer to the invoked code object. And, "self" should
never exist if the object wasn't invoked as a method. (Yes, it should
give a more helpful error message.)
Personally, I'd like to eliminate the automatic "self" keyword entirely,
and replace it with an explicit parameter declaration:
.param pmc self :invocant
But, this is an issue for 1.5, not 1.0.
Allison
More information about the parrot-dev
mailing list