Use an equal sign to assign values to variables.
i1 : x = "abcde" |
i2 : x |
Before assignment, any reference to a variable provides the symbol with that name. After assignment, the assigned value is provided. The variable created is global, in the sense that any code placed elsewhere that contains a reference to a variable called x will refer to the one we just set.
It is important to distinguish between a symbol and its value. The initial value of a global symbol is the symbol itself, and the initial value of a local variable is null. One possibility for confusion comes from the possibility of having a symbol whose value is another symbol; it's even more confusing if the two symbols have the same name but different scopes, for example, if one of them is global and the other is local.
i3 : y |
i4 : y = z |
i5 : y |
i6 : z = 444 |
i7 : z |
i8 : y |
In the example above, the final value of y is the symbol z, even though the symbol z has acquired a value of its own. The function value can be used to get the value of a symbol.
i9 : value y |
The operator <- can be used to set the value of a symbol. This operator differs from = in that the symbol or expression on the left hand side is evaluated.
i10 : y <- 555 |
i11 : y |
i12 : z |
i13 : y = 666 |
i14 : y |
i15 : z |
One reason the user needs to understand this concept is that assignments with the operator <- are occasionally done on the user's behalf by bits of code already in the system, for example, when creating a polynomial ring the prospective variables are given new values which are the generators of the polynomial ring.
See also: