[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]

Re: inherted overload & mixed type operations



On Mon, Jan 10, 2000 at 09:18:25PM +0100, Marc Lehmann wrote:
> On Sun, Jan 09, 2000 at 08:57:21PM -0500, Ilya Zakharevich <ilya@math.ohio-state.edu> wrote:
> > > a) would it be (computationally) feasible to detect this case and use
> > >    the subclass operator always?
> > 
> > Yes.  PDL overloaded multiplication can (and should) do it.
> 
> No, I asked wether the subclass operator could be used all the time, on
> the assumption that the subclass knows about itself, but it's superclass
> does not know (cannot know) anything about it's subclasses.

But you knew the answer already, did not you?

> One way to "fix" this would be for PDL::Complex to overwrite the operators
> of it's superclass, but.....
> 
> > > b) would it make sense except for obvious cases like complex and real-valued
> > >    types?
> > 
> > Polymorphism by two arguments is always a tricky topic.
> 
> Well, other languages do not share this problem, since they do not
> overload based on one of the operands chosen randomly.

Which "other languages" do you have in mind here?  

And there is no randomness whatsoever in the Perl algo: left argument
is the object, right (if applicable) is the argument of the method.
If not possible, invert.

> But indeed it *is*
> a tricky problem.
> 
> Especially when perl acts _totally_ randomly. For example:
> 
>    $sin = i * zeroes(50)->xlinvals(2,4) + 5
> 
> uses the PDL::Complex-*, while
> 
>    $sin = i * zeroes(50)->xlinvals(2,4)
> 
> uses the PDL-* operator.

If i() returns an overloaded object, the *-method for this object will
be called.  If you can demonstrate otherwise, it is a bug.

But are you sure you defined sub i with prototype ''?  If yes, I may
need to look into what you wrote again.  Currently I skept the rest of
your message.

Ilya


Follow-Ups from:
Marc Lehmann <marc@gimp.org>
Christian Soeller <c.soeller@auckland.ac.nz>
References to:
Marc Lehmann <marc@gimp.org>
Ilya Zakharevich <ilya@math.ohio-state.edu>
Marc Lehmann <marc@gimp.org>

[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]