[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 03:31:56PM -0500, Ilya Zakharevich <ilya@math.ohio-state.edu> wrote:
> > > 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?

If I already knew the answer would I have asked??? Is something obvious
escaping me here?

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

_No_ other language chooses overloaded functions randomly like perl ;*)
But to be more helpful: C++ (for example) lets you overload based on both
types. I do not advocate C++, though, if you think I am ;)

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

Define "Perl". I currently define it as "perl 5.005_03", and there it acts
totally strange.

> > uses the PDL-* operator.
> 
> If i() returns an overloaded object, the *-method for this object will
> be called.

No. But if that is how it supposed to happen then this is ok. It is a bit
suboptimal, having to overwrite superclass' operators (especially since
there is no documented way to do this!), but at least something to count
on.

> If you can demonstrate otherwise, it is a bug.

See my last mail. I am also looking for a more simple testcase, but it is
difficult to find (and seems to require a few function calls). That the
problem goes away after first usage might indicate some caching bug. For
example:

=============================================================================
use PDL;
use PDL::Complex;

$sin = (i) * (zeroes(50)->xlinvals(2,4)) + 5;
=============================================================================

dies with an error message, since PDL's * is being called, while:

=============================================================================
use PDL;
use PDL::Complex;

eval { $sin = (i) * (zeroes(50)->xlinvals(2,4)) + 5 };
$sin = (i) * (zeroes(50)->xlinvals(2,4)) + 5;
=============================================================================

works.

> But are you sure you defined sub i with prototype ''?  If yes, I may

BEGIN { $i = bless pdl 0,1 }
sub i () { $i };

-- 
      -----==-                                             |
      ----==-- _                                           |
      ---==---(_)__  __ ____  __       Marc Lehmann      +--
      --==---/ / _ \/ // /\ \/ /       pcg@opengroup.org |e|
      -=====/_/_//_/\_,_/ /_/\_\       XX11-RIPE         --+
    The choice of a GNU generation                       |
                                                         |


Follow-Ups from:
Ilya Zakharevich <ilya@math.ohio-state.edu>
References to:
Marc Lehmann <marc@gimp.org>
Ilya Zakharevich <ilya@math.ohio-state.edu>
Marc Lehmann <marc@gimp.org>
Ilya Zakharevich <ilya@math.ohio-state.edu>

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