> Dan,
> 
> I think there is a real problem with your vtable approach.

[ etc etc ]

I think there's an important misconception about tieing and overloading
going on hre which I will attempt to clear up. (Then Dan and co
can point out that I;'m I;m wrong and have just made matters worsse ;-)

First off, people should be very clear that there are two *completely*
different types of tieing and overloading possible in Perl 6, which
I shall call Perl-mode and C-mode for convenience.

Perl 5 only supports Perl-mode tieing and overloading - ie, where
the tied or overloaded functions that get called are Perl functions.
This is slow and heavyweight, but it is easy to code (ie you write
a Perl module with a few functions).
In addition, Perl 6 allows C-mode tieing and overloading. This is where
the tied or overloaded functions that get called are C functions.
This is much more low-level, but much faster. It's also much harder to
code. C-mode tieing and overloading is what vtables are. Ie you
can write a custom data type and have control over how its data is
accessed, and how its data is operated on.

Note also that C-mode overloading and Perl-mode overloading are quite
different at the language level: Perl 5 overloading is really the overloading
of *reference* operators. Ie if you have

my ($a, $b);
my ($ra, $rb) = (\$ra, \$rb);

Then at this point $ra + $rb gives you nonsense (last time I looked, it
returned the sum of the 2 addresses).

Now if you bless $a, $b into some overloaded class, then
$ra + $rb suddenly starts doing what you want - ie you have overloaded
the defintion of addition *on references*.
Importantly, $a + $b still doesnt do what you want.

Under Perl 6, with C-mode overloading, $a + $b *will* DWIM.

Interestingly enough, perl-mode tieing and overloading will presumably
be implemented using vtables.

For example, when you call the add() vtable method associated with
a tied variable, that add() method just calls the (Perl) FETCH function
from the relevant module, then just passes control on to the add() vtable
method associated with the PMC returned by FETCH, passing through the
original args.

Thus, the only(-ish) place within the perl src that needs to understand
about Perl-mode ties and overloading is within a handful vtable classes


Reply via email to