copy on write

  • Thread starter Eduardo Suarez-Santana
  • Start date
8

88888 Dihedral

在 2012å¹´1月14日星期六UTC+8上åˆ6æ—¶48分29秒,Evan Driscoll写é“:
Well, in any associative operation with an identity implemented in a computer language personally I believe the operator overloading part in C++ is another teasing trick.


Do we have to work out the algebra here?
 
8

88888 Dihedral

在 2012å¹´1月14日星期六UTC+8上åˆ6æ—¶48分29秒,Evan Driscoll写é“:
Well, in any associative operation with an identity implemented in a computer language personally I believe the operator overloading part in C++ is another teasing trick.


Do we have to work out the algebra here?
 
W

Wolfram Hinderer

But isn't it equally true if we say that z = t[1], then t[1] += x is syntactic sugar for z = z.__iadd__(x)? Why should that fail, if z can handle it?

It's more like syntactic sugar for
y = t; z = y.__getitem__(1); z.__iadd__(x); y.__setitem__(1, z)

It's clear that only the last expression fails, after the mutation has
taken place.

Just in case you wonder about the y: you need it for more complicated
cases.
t[1][1] += [4] is syntactic sugar for
y = t.__getitem__(1); z = y.__getitem__(1); z.__iadd__([4]);
y.__setitem__(1, z)

That makes clear why there's no exception in this code:
t = (0, [1, [2, 3]])
t[1][1] += [4]
t
(0, [1, [2, 3, 4]])
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top