User Tools

Site Tools


crpl:docs:deepcopylist

<- CRPL reference <- Lists

DeepCopyList

ArgumentsResultNotation
a list a different list L1 – L2

Description

Creates a new list with the same contents as the old list. Changes to the new list will not change the old list. However, unlike CopyList, lists inside this list will also be copied, so the different lists will be inside both lists. Changing one of these inner lists will not affect the same inner lists in the other list.

Examples

ShowTraceLog
ClearTraceLog

CreateList ->a
CreateList ->b
CreateList ->c
#Stuff lists b and c and a number into a.
<-a <-b AppendToList
<-a <-c AppendToList
<-a 4 AppendToList
#Give b and c some contents.
<-b 9 AppendToList
<-c "hello" AppendToList

#Make copies. How many lists do we have? hint:7
<-a CopyList ->a2
<-a DeepCopyList ->a3

#Show that a is not the same as either a2 or a3.
<-a "weird" AppendToList
#Show that b inside a2 is the same as b inside a.
<-a2 0 GetListElement "goo" AppendToList
#Show that c inside a3 is not the same as c inside a.
<-a3 1 GetListElement "creeper" AppendToList

<-a Trace #[[9,"goo"],["hello"],4,"weird"]
<-a2 Trace #[[9,"goo"],["hello"],4]
<-a3 Trace #[[9],["hello","creeper"],4]
crpl/docs/deepcopylist.txt · Last modified: 2021/02/05 11:45 by Karsten75