Previous Up Next

12.2.10  The difference between := and =<

The := and =< assignment operators have different effects when they are used to modify an element of a list contained in a variable, since =< modifies the element by reference. Otherwise, they will have the same effect.


Example.
Input:

A:= [1,2,3]

Here:

A[1]:= 5

and

A[1] =< 5

both change A[1] to 5:
Input:

A

Output:


1,5,3

but they do it in different ways. The command A[1] =< 5 changes the middle value in the list that A originally pointed to, and so any other variable pointing to the list will be changed, but A[1]:= 5 will create a duplicate list with the middle element of 5, and so any other variable pointing to the original list won’t be affected.


Examples.

If B is set equal to a copy of A instead of A, then changing B won’t affect A.


Example.
Input:

A:=[0,1,2,3,4] B:=copy(A) B[3]=<33 A,B

Output:


0,1,2,3,4
,
0,1,2,33,4

Previous Up Next