David Mitchell wrote:
> 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).
>

Actually, I think Perl 5 supports tying in C level, through sv_magic. I
think overloading is also possible, however I've never seen documentation on
that.

>
> 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.
> [...]
> Interestingly enough, perl-mode tieing and overloading will presumably
> be implemented using vtables.
> [...]
> 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
>

This is exactly what I was talking about, but Dan told me that's not what he
wants with vtables. At least I see I'm not the only one with this wrong
idea...

>
> 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
>

Agreed. Don't see why Perl 6 shouldn't be different, e.g. have "foo" with a
+ overloaded to do concatenation.

>
> 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.
>

But then I don't see how vtables will propagate in an assignment. If $b has
a bigint and I do $a = $b, $a should copy the add/subtract/mul/... entries
of $b's vtable, because without them a bigint doesn't really make sense. In
the other side, if $a copies $b's vtable, and $b is tied to something, $a
will be tied to the thing $b is tied to, what is wrong, since this is an
assignment and not an aliasing. Copying and not copying is not possible.
Copying partially (only add/subtract/mul/...) is only possible if the
entries are in separate vtables, since there are probably many PMC's
pointing to one vtable (meaning it shouldn't be modified) and creating
per-variable vtables is a bad idea (it's just like saying to the user he has
a 256-byte (or more) storage to a 32-bit integer, because of all vtable
entries).

>
> 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.
>

Tying is clear to me. I only see a problem with overloading on assignment,
that clearly cannot co-exist with tie, as I explained above.

- Branden

Reply via email to