Previous Up Next

3.3.3  Assignment by reference

A list is simply a sequence of values separated by commas and delimited by [ and ] (see Section 6.1). Suppose you give the variable a the value [1,1,3,4,5]:

a:=[1,1,3,4,5]

If you later assign to a the value [1,2,3,4,5], then a new list is created. It may be better to just change the second value in the original list by reference. This can be done with the =< command. Recalling that lists are indexed beginning at 0, the command

a[1]=<2

will simply change the value of the second element of the list instead of creating a new list, and is a more efficient way to change the value of a to [1,2,3,4,5].


Previous Up Next