Going about (finally) implementing my Infinity pmc, I noticed a lot of
redundant code in the Perl* classes.  For instance, the polymorphic
behavior isn't implemented in PerlScalar, but rather in each of its
subclasses, which seems to rather defeat the purpose of making them
subclasses.

However, trying to move the functionality up to PerlScalar just got me
in more trouble, where seemingly unrelated tests would fail, &c.  So
is it some implementation detail that we can't put these up in
PerlScalar?  Maybe I just did something wrong that I didn't see.

But on a longer-term note, is this the way we really should be doing
it?  I mean, after all, it's not a PerlInteger that's polymorphic,
it's the container -- the integer is just the value it holds.  Putting
the polymorphism in the value type somewhat precludes storing any
other kind of PMC in a Perl scalar. (Maybe that's a good thing... I'm
not entirely sure of how people are envisioning scalars to work with
everything else).

The way I see this being done is by adding another level of
indirection.  PerlScalar would implement its polymorphic behavior in
the set_* methods, and delegate everything else to its "contained"
pmc.  Things like TiedScalar would do the same, but it would delegate
to methods on its contained object, &c.

Of course, there is a slight added cost for the extra level of
indirection, but it's worth it IMO.  Is this worth persuing?

Luke

Reply via email to