On Thu, Sep 24, 2009 at 12:45:13AM -0700, Carl Mäsak wrote:
> <masak> rakudo: sub foo { say "OH HAI" }; class A { method bar {} };
> &A::bar = &foo; A.new.bar
> <p6eval> rakudo 0eaf62: OUTPUT«OH HAI»
> <jnthn> oh cunning
> <moritz_> !
> <masak> monkey typing without the monkey.
> * Matt-W sees nothing wrong with that
> <masak> Matt-W: are you quite serious?
> <jnthn> I'm not sure it's wrong either.
> [...]ISTR another conversation on IRC [1] where it was indicated that one cannot assign to a subroutine as done above; the symbol can only be rebound. So the "&A::bar = &foo;" line above should probably throw a "cannot modify read-only value" exception. [1] http://irclog.perlgeek.de/perl6/2009-07-21#i_1331026 (Yes, Routines are considered mutable, but I think that's only for wrapping purposes. I don't think one is allowed to directly assign to a Routine object.) Beyond that, the reason why the above fails is because of the long-standing Parrot bug that incorrectly puts methods into the package namespace (TT #389 I think). In other words, Parrot acts as if all methods have an "is export" trait on them. So, assigning to &A::bar (incorrectly bound to the method) ends up having the side effect of modifying the method, when the two really should be disconnected. Note that binding wouldn't be a problem. Pm
