Last update July 2, 2007

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
a standard deep copy could be achieved by a recursive shallow copy, which stops at the primitave types (note: primitave types should be more OO)

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 are

Binary copy operators:

  • a := b
  • a <- b
  • a @= b
Unary clone operators:
  • a = b.dup (just make dup universal)
  • a = :b
  • a = @b
  • a = *b (probably a bad idea, since this conflicts with pointer dereferencing)

FrontPage | News | TestPage | MessageBoard | Search | Contributors | Folders | Index | Help | Preferences | Edit

Edit text of this page (date of last change: July 2, 2007 17:34 (diff))