Before 0.9.507.0 Vizzy used to pass lists as reference, so we had the following behavior:
list"A"
set "B" to "A"
Change the value of "B", and "A" will change
This was changed and now a copy is passed in set X to Y
and also when calling a custom instruction. There are however some legitimate use cases when an instruction/function should operate on the original list, as I explained in bug report.
After the rather unfortunate change (it broke my program) I can see 2 ways how list passing could work in Vizzy:
set X to Y
makes a copy by default. If you want to have X reference the same list as Y then some expression (a marker) should be added to Vizzy, let's saybyReference
. Then we could use it:
- When setting variables:
set X to byReference(Y)
. - When calling custom instructions/functions:
myCustomInstruction(arg1, arg2, byReference(myList1), myList2)
. myList1 is passed by reference and myList2 by copy.
- When setting variables:
- Revert the bug fix so that
set X to Y
makes a reference. Function calls would also pass lists by reference. If you want to have a copy of your list then some new expression is needed, saycopyOf
. Then you could:
- set variable to a copy of list:
set X to copyOf(Y)
- call a custom function/instruction:
myCustomInstruction(arg1, arg2, myList1, copyOf(myList2))
. As in previous point, myList1 is passed by reference and myList2 by copy.
- set variable to a copy of list:
For me the solution 2. seems more natural. It's actually the way used in many real programming languages. In Python for example we have operation like copyOf
, but there is also sth like deepCopyOf
which works like: when you have a list of lists, it'll make a copy of those inner lists too (recursive copy). Unlike copyOf
, which should copy only the outer list, but its elements should be references to elements of the original list.
It seems I should have used Development -> Suggestions instead of the forum with "Suggestion" tag. There it is: Vizzy: pass-by-reference for lists.