Hello All,
In reading over the Synopsis again in hopes of finding more
information regarding the different repr types (see the warnocked
post entitled "Construction and Initialization of repr types other
than P6opaque"), I stumbled onto some issues with the Perl 6 OO model
and &bless.
In S02 it says:
Perl 6 is an OO engine, but you're not generally required to
think in OO
when that's inconvenient. However, some built-in concepts such
as filehandles
will be more object-oriented in a user-visible way than in Perl 5.
Now taking this statement one (logical) step further, and I assume
that this means things like arrays and hashes will (underneath) just
be objects. So we will have an ^Array class, and a ^Hash class, and
[] and {} will actually construct instances of ^Array and ^Hash
respectively. (Of course I am simplifying it here, these may be roles
instead of classes, but this is not relevant to the discussion really).
Then later on S12 says:
As in Perl 5, a constructor is any routine that calls bless.
Unlike in Perl 5,
you call it as a method on the class, passing the candidate as
the first
argument. To bless a hash as in Perl 5, say:
$object = $class.bless({k1 => $v1, k2 => $v2, ...});
Are we not just re-blessing an instance of the class ^Hash into
whatever $class is? That does not seem to be what is intended,
however, if {} is a constructor for an instance of ^Hash, and I can
call methods on {} like any other object ({}.keys, {}.exists($key),
etc.), then what happens when I bless {} with a class? Do I loose
access to the methods of ^Hash? Are the methods only allowed to be
called in the non-invocant syntax (called like functions and not
methods)?
Which brings me to my real question:
Do we really still need to retain the old Perl 5 version of &bless?
What purpose does it serve that p6opaque does not do in a better/
faster/cleaner way?
Thanks,
Stevan