55 lines
1.3 KiB
Plaintext
55 lines
1.3 KiB
Plaintext
link printf,ximage
|
|
|
|
procedure main()
|
|
|
|
knot := makeknot() # create a structure with loops
|
|
knota := knot # copy by assignment (reference)
|
|
knotc := copy(knot) # built-in copy (shallow)
|
|
knotdc := deepcopy(knot) # deep copy
|
|
|
|
|
|
showdeep("knota (assignment) vs. knot",knota,knot)
|
|
showdeep("knotc (copy) vs. knot",knotc,knot)
|
|
showdeep("knotdc (deepcopy) vs. knot",knotdc,knot)
|
|
|
|
xdump("knot (original)",knot)
|
|
xdump("knota (assignment)",knota)
|
|
xdump("knotc (copy)",knotc)
|
|
xdump("knotdc (deepcopy)",knotdc)
|
|
end
|
|
|
|
record rec1(a,b,c) # record for example
|
|
|
|
class Class1(a1,a2) # class - looks like a record under the covers
|
|
method one()
|
|
self.a1 := 1
|
|
return
|
|
end
|
|
initially
|
|
self.a1 := 0
|
|
end
|
|
|
|
|
|
procedure makeknot() #: return a homogeneous structure with loops
|
|
L := [9,8,7]
|
|
T := table()
|
|
T["a"] := 1
|
|
R := rec1(T)
|
|
S := set(R)
|
|
C := Class1()
|
|
C.one()
|
|
T["knot"] := [L,R,S,C]
|
|
put(L,R,S,T,C)
|
|
return L
|
|
end
|
|
|
|
procedure showdeep(tag,XC,X) #: demo to show (non-)equivalence of list elements
|
|
printf("Analysis of copy depth for %s:\n",tag)
|
|
showequiv(XC,X)
|
|
every showequiv(XC[i := 1 to *X],X[i])
|
|
end
|
|
|
|
procedure showequiv(x,y) #: show (non-)equivalence of two values
|
|
return printf(" %i %s %i\n",x,if x === y then "===" else "~===",y)
|
|
end
|