Deepcopy: Difference between revisions

797 bytes added ,  12 years ago
J
m (→‎{{header|Ruby}}: Swap 2 words.)
(J)
Line 187:
L11[7] := R_Class1__state_2
...</pre>
 
=={{header|J}}==
 
J uses pass by value semantics (typically implemented as copy on write) so Deepcopy is trivial -- values inside the language are immutable.
 
That said, J can reference values outside the language. But Deepcopy of those values is, by definition, outside the scope of the language. Usually, bringing the values into the language is sufficient.
 
Another possible exception would be classes and objects (which are not values but collections of references to values). But as a general rule copying of an object should be delegated to the object itself rather than imposed from the outside. Also, "deepcopy" violates the Law of Demeter as well as the concept of black-box reuse -- if you need deepcopy in J, you probably should not be representing your data structure as objects.
 
=={{header|Ruby}}==
6,962

edits