(*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
USING LISTS: COPY VS SET
-----------------------------------------------------
If you use "set", the new list will just create a reference to the original
Then, if you change the new list, it also changes the old list, and vise-versa
BEST PRACTICE:
• Use COPY unless you need a reference to original list
copy origList to newList
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*)
----------------------------------
### EXAMPLE USING SET LIST ###
----------------------------------
set
origList
to {"one",
"two", "three"}
----------------------------
set
newList to
origList
----------------------------
set
item 2
of
newList to
"changed from newList"
set
item 3
of
origList
to "changed from origList"
-- At this point both origList and newList have been changed,
-- and both are identical.
origList
--> {"one", "changed from newList", "changed from origList"}
newList
--> {"one", "changed from newList", "changed from origList"}
----------------------------------
### EXAMPLE USING COPY LIST ###
----------------------------------
-- If you use "copy", then the new list will be independent
-- from the original list
set
origList
to {"four",
"five", "six"}
----------------------------
copy
origList to
newList
----------------------------
set
item 2
of
newList to
"changed from newList"
set
item 3
of
origList
to "changed from origList"
-- Both lists have been changed, but have NO effect on one another
origList
--> {"four", "five", "changed from origList"}
newList
--> {"four", "changed from newList", "six"}