I'm not certain of the language to use for describing the issue I've encountered, so I'll just illustrate it with an example.
Essentially, it seems that variable assignment with arrays works differently from variable assignment with non-arrays.
Example 1: numbers (behaviour = expected behaviour; description below):
(%i4) foo1:0$
bar1:foo1$
bar1:1$
foo1;
(%o4) 0
Here, I've assigned bar1
to foo1
and then reassigned bar1
to 1
and then returned foo1
. As expected, the value of foo1
has not been changed.
Example 2: lists (behaviour = expected behaviour; description below):
(%i8) foo2:[0,0]$
bar2:foo2[1]$
bar2:1$
foo2;
(%o8) [0,0]
Same idea as example 1, but with lists. N.B. the behaviour is the same if bar2:foo2
and bar2:[1,0]
, so I didn't include that case, here.
Example 3: array (behaviour != expected behaviour; description below)
(%i12) foo3:[[0,0], [0,0]]$
bar3:foo3[1]$
bar3[1]:1$
foo3;
(%o12) [[1,0],[0,0]]
Here it seems that an assignment of an element of the list bar3
also affects an the original array foo3
.
I didn't think variable assignment worked like this -- it seems like an inconsistency to me; however, I have very little experience with programming.
Any insight would be greatly appreciated!