Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^7: A little overloading conundrum

by syphilis (Archbishop)
on Mar 15, 2026 at 14:39 UTC ( [id://11167467]=note: print w/replies, xml ) Need Help??


in reply to Re^6: A little overloading conundrum
in thread A little overloading conundrum

Thanks for the reply. (I haven't been able to access this webshite for the last 3 days.)
I was a bit confused by the fact that, with Choroba's script, the overloading was unaffected by the order in which package My::A and My::B were listed.
Eventually, I deduced that the overriding "use overload" directives were, courtesy of being inside an eval block, not executed until after both packages had loaded.
Anyway, I've been playing around with this approach and finding it to be relatively simple.

I've decided that the implementation should be effected by a standalone module (Math::GMP_OLOAD) which will handle the Math::GMP side of things regarding the handling of Math::GMP objects in Math::MPFR, Math::GMPq and Math::GMPz. So it will contain stuff like:
{ package Math::GMP; use overload "+" => sub ($$$) { my($x, $y) = (shift, shift); if(ref($y) eq 'Math::MPFR' || ref($y) eq 'Math::GMPq' || ref($y) + eq 'Math::GMPz') { return $y + $x; } return Math::GMP::op_add($x, $y, 0); }; use overload "-" => sub ($$$) { my($x, $y) = (shift, shift); if(ref($y) eq 'Math::MPFR' || ref($y) eq 'Math::GMPq' || ref($y) + eq 'Math::GMPz') { return -($y - $x); } return Math::GMP::op_sub($x, $y, shift); }; ....
Seems to be working ok.
I doubt that anyone else will make much use of it, but I might use it a bit - and it's an enjoyable little exercise, anyway.
It's nearly all done outside of the 3 modules it's supporting - ie it adds negligible clutter to those 3 modules.

Cheers,
Rob

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11167467]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2026-04-19 21:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.