A uniformly applicable copy operator would be useful.
Such a thing should be automatically generated by the compiler to perform a shallow copy of classes, but could be overridden to modify the way the copy is created. Currently
- 'a = b' is a shallow copy for structs.
- 'a = b.dup' is a shallow copy for arrays.
- there is no standard copy for classes.
- there is no standard mechanism for a deep copy
There's a subtle difference between a binary copy operator, and a unary duplication operator. The latter lets you change how the copying is performed based on context, so that e.g. one object can be "copied" onto an object of different type.
There could be a new operator introduced that does a shallow copy for any of the above. Some suggestions are
Binary copy operators:
- a := b
- a <- b
- a @= b
- a = b.dup (just make dup universal)
- a = :b
- a = @b
- a = *b (probably a bad idea, since this conflicts with pointer dereferencing)