Chaim Frenkel <[EMAIL PROTECTED]> writes:
>>>>>> "NI" == Nick Ing-Simmons <[EMAIL PROTECTED]> writes:
>
>NI> If it has to be static then name => index has to be global across all classes
>NI> as ISA tree adds leaves and reconverges.
>
>Run this one by me again. Why isn't it enough to have the integers depend
>only on the _current_ @ISA? So it would be per package.
OK - Consider - two @ISA trees rooted in Base1 and Base2:
package Base1;
sub one; # index = 1
sub two # index = 2
{
shift->one + 1; # shift->#1+1
}
package Dervived1;
use base 'base1';
sub three; # index = 3;
package Base2;
sub A # index = 1;
{
}
sub B # index = 2;
{
return shift->A - 42; # s->#1 - 42
}
sub C; # index = 3;
package Dervied2;
sub three # index = 4;
{
my $self = shift;
return $self->A - $self->C; # ->#1 - ->#3
}
Runs for two days then something causes this to be loaded:
package Dervied3
use base qw(Derived2 Derived1);
sub B
{
my $self = shift;
return $self->three+$self->two;
}
Now that is suppsed to call Derived2::three and Base1::two
->#1(A) - ->#3(C) + -#1(one) + 1
If slot#1 is compiled in to both Base1::two and Derived2::three
there is a conflict for Derived3::#1 slot:
should it be 'one' inherited from Base1 via Derived1
or 'A' inherited from Base2 via Derived2 ?
The two disjoint @ISA trees can be re-converged at any time as a new
derived class is defined. So numbers have to be global.
>
>NI> Op could have a static name and lookup in a hash ;-)
>
>True. But a pointer+offset is probably a bit faster.
Of course.
>
>>> You seem to think that that's not feasible.
>
>NI> See my earlier summary - static index is possible if mapping is global,
>NI> then vtable is sparse.
>
>vtbl would be compact. The values can be precomputed.
No they can't - you don't know what is going to happen later.
>
>How about for static @ISA
The @ISA's above are all static - once set they never change.
But the _trees_ are not static - when my children get married
I get to hob-nob with the inlaws. If Grandad A is a pork butcher
and Grandad B a Rabbi what gets served at the wedding feast is going
to anoy one of them...
>and static ->method calls, compile time and
>for really hairy Tk type systems, we stick with dynamic hash lookups
>and a hash.
But how do we tell that "I am never going to be inherited by something"
so I can compile this code to use index.
>
>I'd imagine that the static case would be more prevelent.
In mono-lithic C++ apps yes.
>And making
>the dynamic version take a hit.
Which means just about any perl OO.
--
Nick Ing-Simmons