On Mon, Oct 24, 2005 at 06:33:20AM -0700, Ashley Winters wrote:
: # behavior through prototype -- guessing realistic syntax
: Base.meta.add_method(
:     do_it => method ($arg) {
:         say "doing $arg!";
:     });
: 
: 
: # or, just add it to a single instance
: $x.meta.add_method(
:     do_it => method ($arg) {
:         say "doing $arg!";
:     });

I don't have a comment on your actual question, but I'd like to use
this opportunity to point out the symmetry of Base and $x at this
point, and the fact that .meta can't simply call .add_method in the
metaclass, or it would lose track of the original invocant, which is
needed to convey both class and instance information.  I'm not sure
it's even possible to say

    $m = $x.meta;
    $m.addmethod($arg);

The only way that can work is if $x.meta returns a shadow class that
is prebound only to $x.  (Though that might explain how .addmethod
knows it's only adding a method to the object.)

In the absence of that, what's going on seems more like

    $x.META::addmethod($arg);

where META:: is smart enough to dispatch to the proper metaclass without
throwing away the invocant, and then the metaclass decides what to do
based on the instancehood of $x.

Larry

Reply via email to