This is perfectly possible in Perl5, so I don't see why it wouldn't be
possible in Perl6...

Create a new package.
Add the sub to that package.
Set the @INC of that package to your current package.
Re-bless yourself into the new package.

Granted a nice simple syntax would be nice, but that's what modules are
for.

You also run into issues of identity. If I add a method to an existing
object, is that object still of the same type? Should 'ref' return the
same classname, or is it okay if it returns some auto-generated name after
it's had instance methods added to it? The latter would occur with the
Perl5 solution above, and I would argue that it should stay that way,
since it's not exactly the same type.

Mike Lambert


Luke Palmer wrote:

> Date: Wed, 15 May 2002 19:51:39 -0600 (MDT)
> From: Luke Palmer <[EMAIL PROTECTED]>
> To: [EMAIL PROTECTED]
> Subject: Methods, and such
>
> It seems something messed up while I tried to send this earlier. If this
> is essentially a duplicate, ignore it.
>
> I've always liked how VB allowed you to do "instance methods." They allow
> for more elegant callbacks, and more structure if callbacks are
> complicated. Will Perl6 allow this? (Perl5 sortof did, but since the
> "bless" way of life is going away...)
>
> Perhaps...
>
>  class foo {...}
>
>  $x = new foo;      #BTW: is there some unified way of creating instances
>                   # in perl6?
>  method $x.frob() {...}
>
>  $x.frob;
>
>
>
> Luke
>
>

Reply via email to