Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^6: How does Math::GMP overload the assignment operator ?

by syphilis (Bishop)
on Nov 09, 2020 at 13:52 UTC ( #11123525=note: print w/replies, xml ) Need Help??


in reply to Re^5: How does Math::GMP overload the assignment operator ?
in thread How does Math::GMP overload the assignment operator ?

The real solution to this is to make your objects immutable

That (along with the elaboration you've provided) seems to be describing exactly what Math::GMP does.
And yet Math::GMP also sets that very same troublesome trap wrt overloading '=' that I find disconcerting.
So, I'm left wondering just what it is that this "solution" solves.

I'll point out that I don't mean that last sentence to sound as smartarsey as it does. Deep down I know the problem is that I'm being dense.

Cheers,
Rob
  • Comment on Re^6: How does Math::GMP overload the assignment operator ?

Replies are listed 'Best First'.
Re^7: How does Math::GMP overload the assignment operator ?
by Haarg (Curate) on Nov 09, 2020 at 17:42 UTC

    It's not immutable. It provides an add_ui_gmp method that mutates the object. If it was actually immutable, there wouldn't be any trap because it wouldn't really matter if you cloned objects or not when using them in multiple places.

      It's not immutable. It provides an add_ui_gmp method ...

      Aaah - when I saw "methods" in your earlier post I was thinking that you meant "ways of overloading" ... but, of course, when you said "methods" you meant "methods".
      Your post makes perfect sense. (Did I mention that I might have had an inkling that I was being dense ? ;-)

      It's an interesting idea and thanks muchly for presenting it.
      However, for my own modules, I think I'll be sticking with the functions that permit objects to mutate.
      Creating new objects all of the time sounds expensive ... though I haven't done any tests on the costs.

      Cheers,
      Rob

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (1)
As of 2021-10-16 15:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (69 votes). Check out past polls.

    Notices?