On 02/07/01 Edwin Steiner wrote:
> [snip]
> 
> I thought about it once more. Maybe I was confused by the *constant* NATIVE.
> Are you suggesting a kind of multiple dispatch (first operand selects
> the vtable, second operand selects the slot in the vtable)?
> 
> So
>     $dest = $first + $second
> becomes
>     first->vtable->add[second->vtable->type(second)](dest,first,second,key);
> ?
> 
> or maybe
>     first->vtable->add[second->vtable->slot_select](dest,first,second,key);
> which saves a call by directly reading an integer from the vtable of <second>.
> 
> (BTW, this is also how overloading with respect to the second argument
> could be handled (should it be decided on the language level to do that):
> There could be a slot like add[ARCANE_MAGIC] selected by
> second->vtable->slot_select
> which does all kinds of complicated checks and branches without any cost
> for the vfunctions in the other slots.)
> 
> Such a multiple dispatch seems to me like the only solution which avoids
> the following (eg. in Python):
>     'first + second' becomes
>       1. call virtual function 'add' on <first>
>       2. inside first->add do lots of checks about type of <second>

Something like what's done in python looks sensible to me.
If a vtable add function is also indexed by type you get exponential
growth of the vtable with the addition of other types and we want to
make that easy in perl 6. Also, it doesn't work if I introduce
my bigint type (the internal int vtable knows nothing about it):

        $int = 1;
        $bigint = new bigint ("9" x 999);
        $res = $bigint + $int; # works, bigint knows about internal int
        $res = $int + $bigint; # doesn't work, since the bigint is the second arg

The proposed solution (used in elestic, for example) is to have the add
method return a value indicating it has performed the addition: if it's
false, we try to add using the add method in the second argument that may 
know better...
In the method, you check the types and perform the work only on the
ones you know about.

lupus

-- 
-----------------------------------------------------------------
[EMAIL PROTECTED]                                     debian/rules
[EMAIL PROTECTED]                             Monkeys do it better

Reply via email to