deepcopy - create a deep (recursive) copy of a value
val.deepcopy()
The deepcopy method creates a deep (recursive) copy of a
value. This is the same as the @@ operator.
Note that the deepcopy method is used to overload the
@@ operator.
A new deep copy of the value
None
// The copy method is a shallow copy
a = {{1,2},3,4}
b = a.copy()
b[0][1] = 20
a
+----+ 3 4
|1 20|
+----+
// The deepcopy method copies recursively
b = a.deepcopy()
b[0][1] = 200
a
+----+ 3 4
|1 20|
+----+
b
+-----+ 3 4
|1 200|
+-----+
// The deepcopy method is used to overload the "@@" operator
class foo {
var a;
public proc create(arr) { a = arr; }
public proc copy() {
"Copying!\n";
return new foo(a);
}
}
#edit foo
x = new foo("hello")
y = @@x
Deep Copying!