assignment to symbols
-
- Inputs:
- Consequences:
- assuming the value of x is a symbol, t, say, the value of e is assigned to t so that future references to the value of t yield e.
- Outputs:
- the value of the expression is the value of e
i1 : x = t
o1 = t
o1 : Symbol
|
i2 : x <- 4
o2 = 4
|
i3 : x
o3 = t
o3 : Symbol
|
i4 : t
o4 = 4
|
Initially, the value of a symbol y is y itself, and then y = e and y <- e do the same thing.
i5 : y <- 44
o5 = 44
|
i6 : y
o6 = 44
|
The code to the left of the arrow can be any expression whose value is a symbol.
i7 : f = () -> symbol z
o7 = f
o7 : FunctionClosure
|
i8 : (f()) <- 44
o8 = 44
|
i9 : z
o9 = 44
|
installing new assignment methods
- Usage:
installMethod(symbol <-, X, (x,e) -> ...)
- Inputs:
- Consequences:
- the function (x,e) -> ... is installed as the method for assignment to objects of type X. See the next subsection below for using it.
- Outputs:
- the value returned is the function provided
i10 : installMethod(symbol <-, String, peek)
o10 = peek
o10 : FunctionClosure
|
using installed assignment methods
-
- Inputs:
- x, an object of type X
- e, a thing
- Consequences:
- the previously installed method for assignment to objects of type X is called with arguments (x,e), unless x is a symbol, in which case the internal assignment method applies, as described above. If there is no method for X, then the ancestors of X are consulted, starting with the parent of X and ending with Thing (see inheritance).
- Outputs:
- the value of the expression is the value returned by the previously installed method
The following example used the method for assignment to strings installed above.
i11 : "foo" <- "bar"
o11 = ("foo", "bar")
|
As before, the left hand side is evaluated, and in this case, it can be any expression whose value is a string.
i12 : "foo" | "foo" <- "bar"
o12 = ("foofoo", "bar")
|
assignment to an indexed variable
-
- Inputs:
- Consequences:
- assuming the value of x is an indexed variable, the value of e is assigned to it, so that future references to value x or to s_i, if that's what the value of x is, yield e. Moreover, the value of s is set to s.
- Outputs:
- the value of the expression is the value returned by the previously installed method
This assignment method is pre-installed.
i13 : u = s_4
o13 = s
4
o13 : IndexedVariable
|
i14 : s = 3
o14 = 3
|
i15 : u <- 555
o15 = 555
|
i16 : s
o16 = s
o16 : Symbol
|
i17 : s_4
o17 = 555
|
i18 : u
o18 = s
4
o18 : IndexedVariable
|
i19 : value u
o19 = 555
|