In this section we'll discuss simple assignment to variables, multiple assignment, assignment to parts of objects, assignment covered by various other methods, and briefly touch on the possibility of custom installation of assignment methods. See also the operator :=, which handles assignment and declaration of local variables and assignment of methods to operators, as well as the operator <-, which is an assignment operator that evaluates its left hand side and can have assignment methods installed for it by the user.
x = e
|
|
|
Since the value of the entire expression is e, and since the operator = is right-associative (see precedence of operators), e can be easily assigned to more than one variable, as in the following example.
|
|
|
(x,y,z,...) = (c,d,e,...)Multiple assignment makes it easy to switch the values of two variables, or to permute the values of several.
|
|
|
|
|
Multiple assignment enables functions to return multiple values usefully. See making functions with multiple return values.
|
|
|
|
Multiple assignment may also be used for other uses of = such as assigning to elements of mutable lists and hash tables and using/installing assignment methods.
x#i = e
|
|
|
|
|
|
x#i = e
|
|
|
|
|
|
|
X OP Y = (x,y,e) -> ...
|
|
Warning: the installation of new methods may supplant old ones, changing the behavior of Macaulay2.
x OP y = eThe return value and the consequences depend on the code of the installed assignment method. References to currently installed assignment methods are given below.
The second line of the following example illustrates the syntax above.
|
|
x_i = eThe method for assignment to indexed variables is pre-installed.
|
|
|
|
|
|
|
OP X = (x,e) -> ...
|
|
Warning: the installation of new methods may supplant old ones, changing the behavior of Macaulay2.
OP x = eThe return value and the consequences depend on the code of the installed assignment method. References to currently installed assignment methods are given below.
The second line of the following example illustrates the syntax above.
|
|
X OP = (x,e) -> ...
|
|
Warning: the installation of new methods may supplant old ones, changing the behavior of Macaulay2.
x OP = eThe return value and the consequences depend on the code of the installed assignment method. References to currently installed assignment methods are given below.
The second line of the following example illustrates the syntax above.
|
|
The source of this document is in /build/reproducible-path/macaulay2-1.26.05+ds/M2/Macaulay2/packages/Macaulay2Doc/operators/assignment.m2:392:0.