Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Is object representation "per class" or "per object"?

5 views
Skip to first unread message

Abhijit Mahabal

unread,
Dec 7, 2004, 12:32:50 PM12/7/04
to perl6-l...@perl.org
According to S12, it is possible to supply the object layout to bless(),
like so:

$object = $class.bless(:CREATE[:repr<P6opaque>] :k1($v1) :k2($v2))

But in the section "Introspection", "layout" is a class trait. Does this
mean that classes have a default layout that can be overriden for
individual objects?

If the answer is "yes", what is the reason that somebody would want to
have some objects of the same class as P6Opaque and others as PyDict? I
can imagine needing to be able to *convert* from one layout to another,
but then the converted object appears to me to belong to a different class
(probably in a different language) and then layout should perhaps be an
adverb for something like convert() or cast()*, instead of for bless().

Another reason for saying that the object laid out differently is a
different class is that if for whatever reason you want some object either
as P6Opaque or PyDict then you may also want both representations
simultaneously, effectively requiring "two objects".

What am I missing? A good example of the need of overriding the default
class layout will suffice...

--abhijit

* maybe not even then, because we'd be saying
$current_obj.cast($otherclass), and $otherclass would know it's own
layout.

Abhijit Mahabal http://www.cs.indiana.edu/~amahabal/

Larry Wall

unread,
Dec 8, 2004, 3:23:37 PM12/8/04
to perl6-l...@perl.org
On Tue, Dec 07, 2004 at 12:32:50PM -0500, Abhijit Mahabal wrote:
: According to S12, it is possible to supply the object layout to bless(),
: like so:
:
: $object = $class.bless(:CREATE[:repr<P6opaque>] :k1($v1) :k2($v2))
:
: But in the section "Introspection", "layout" is a class trait. Does this
: mean that classes have a default layout that can be overriden for
: individual objects?

Er, no. It's probably just a braino. If it works at all, I think
it's probably for when the class doesn't specify a layout, or has a
meta-layout that can handle multiple layouts. It might not even make
sense for that. In general, a class should have a consistent layout.

I think I was thinking about the fact that Perl 5's bless can just use
whatever data structure you hand it. So maybe

$object = $class.bless(:CREATE[:repr<P6Hash>] :k1($v1) :k2($v2))

is equivalent to

$object = $class.bless({}, :k1($v1) :k2($v2))

But mostly I was just looking for an example option to pass to :CREATE.
Perhaps :repr is a bit too violent for that.

Larry

0 new messages