Task

Demonstrate how to copy data structures containing complex heterogeneous and cyclic semantics.

This is often referred to as deep copying, and is normally required where structures are mutable and to ensure that independent copies can be manipulated without side-effects.

If this facility is not built into the language, it is permissible to use functions from a common library, or a coded procedure.



The task should show:

 Relevant semantics of structures, such as their homogeneous or heterogeneous properties, or containment of (self- or mutual-reference) cycles.
 Any limitations of the method.
 That the structure and its copy are different.
 Suitable links to external documentation for common libraries.


 
Type DeepCopy
    value1 As Integer
    value2 As String * 1
    value3 As String
    value4 As Boolean
    value5 As Double
End Type
Dim As DeepCopy a, b
 
a.value1 = 10
a.value2 = "A"
a.value3 = "OK"
a.value4 = True
a.value5 = 1.985766472453666
 
b = a
a.value1 = 20
a.value2 = "B"
a.value3 = "NOK"
a.value4 = False
a.value5 = 3.148556644245367
 
Print !"Valor de \"a\":"
Print a.value1
Print a.value2
Print a.value3
Print a.value4
Print a.value5
 
Print !"\nValor \"b\":"
With b
    Print .value1
    Print .value2
    Print .value3
    Print .value4
    Print .value5
End With
Sleep
 