Feature Request List /
Copy Operator
The Issue
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
Discussion
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.
Specification
todo
Syntax
There could be a new operator introduced that does a shallow copy for any of the above. Some suggestions areBinary 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)