At 02:01 PM 12/7/00 +0000, David Mitchell wrote:
>Nicholas Clark <[EMAIL PROTECTED]> wrote:
> > On Thu, Dec 07, 2000 at 01:14:40PM +0000, David Mitchell wrote:
> > > Dan Sugalski <[EMAIL PROTECTED]> wrote:
> >
> > > > All the math is easy if the scalars are of known types. Addition and
> > > > multiplication are easy if only one of the scalars involved is of 
> known
> > > > type. Math with both of unknown type, or subtraction and division 
> with the
> > > > right-hand operand of unknown type, is rather more difficult. :(
> > >
> > > I'm not clear with your scheme how addition works if one of the scalars
> > > (the adder) is of unknown type. ie
> > >
> > > given sv1 of type NUM, sv2 of type UNKNOWN; $sv1 + $sv2 would invoke:
> > >
> > > sv1->add[UNKNOWN](sv2),
> > >
> > > which somewhere will cause a function in the vtable for NUMs to be 
> called,
>eg
> > >
> > > NUM_add_UNKNOWN(sv1,sv2) { .... }
> > > Now, how does does this function perform its calculation?
> >
> > I'm guessing that Dan is planning to take advantage of addition and
> > multiplication being commutative.
> >
> > sv1->add[UNKNOWN](sv2)
> >
> > swaps to
> >
> > sv2->add[NUM](sv1)
> >
> > (It's "obvious" in the usual way - not obvious until you see it. I've been
> > prodding in pp_add in perl5, so I've been thinking about these sort of
> > things)

And all that was what I was thinking.

>My original suggestion was that scalar types provide a method that says
>how 'big' it is (so complex > bigreal > real > int etc),
>and pp_add(), pp_sub() etc use these values to call the method associated
>with the biggest operand, swapping args if necessary (and passing a flag
>indicating that arg swapping has taken place).

Right, but that only works when the two scalar types are in the same line. 
If, for example:

    my Complex $s1 = 4 + 4i;
    my Image $s2 : filename(foo.gif);

    $s3 = $s1 + $s2;

how would you handle the addition if perl doesn't know about complex types? 
You've got two entirely different scalars that really have no basis for 
comparison to judge which is really 'bigger' than the other.

                                        Dan

--------------------------------------"it's like this"-------------------
Dan Sugalski                          even samurai
[EMAIL PROTECTED]                         have teddy bears and even
                                      teddy bears get drunk

Reply via email to