In most cases, the default behavior of augmented assignment gives the desired result. But in some situations, it may be useful to override this behavior and install a custom method for a given type.
Consider the following example.
|
|
|
|
|
|
Note that an intermediate Foo object was created and then assigned to x. Instead, it would be more efficient if x was modified directly.
The first two lines below do exactly the same thing; the second line is syntactic sugar for the first.
|
|
|
In some cases, it may be useful to fall back on the default behavior of the given operator. When this is desired, the installed method should return the Default symbol.
|
|
|
|
|
|
|
|