Skip to content

Commit 9fb67c8

Browse files
authored
Improve deepcopy documentation to clarify reference behavior (JuliaLang#51569)
The original text here: > For example, deep-copying an array produces a new array whose elements are deep copies of the original elements reads to me that its implementation would do something like `deepcopy(array) = [deepcopy(element) for element in array]`. That's the wrong mental model — we preserve relationships. This is tricky to talk about, but I think this gets at the crux of it.
1 parent b790cf8 commit 9fb67c8

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

base/deepcopy.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99
deepcopy(x)
1010
1111
Create a deep copy of `x`: everything is copied recursively, resulting in a fully
12-
independent object. For example, deep-copying an array produces a new array whose elements
13-
are deep copies of the original elements. Calling `deepcopy` on an object should generally
12+
independent object. For example, deep-copying an array creates deep copies of all
13+
the objects it contains and produces a new array with the consistent relationship
14+
structure (e.g., if the first two elements are the same object in the original array,
15+
the first two elements of the new array will also be the same `deepcopy`ed object).
16+
Calling `deepcopy` on an object should generally
1417
have the same effect as serializing and then deserializing it.
1518
1619
While it isn't normally necessary, user-defined types can override the default `deepcopy`

0 commit comments

Comments
 (0)