Mathematica 9 is now available
Previous section-----Next section

A.5.2 Assignments

lhs = rhs immediate assignment: rhs is evaluated at the time of assignment
lhs := rhs delayed assignment: rhs is evaluated when the value of lhs is requested

The two basic types of assignment in Mathematica.

Assignments in Mathematica specify transformation rules for expressions. Every assignment that you make must be associated with a particular Mathematica symbol.

f[args] = rhs assignment is associated with f (downvalue)
t/: f[args] = rhs assignment is associated with t (upvalue)
f[g[args]] ^= rhs assignment is associated with g (upvalue)

Assignments associated with different symbols.

In the case of an assignment like f[args] = rhs, Mathematica looks at f, then the head of f, then the head of that, and so on, until it finds a symbol with which to associate the assignment.

When you make an assignment like lhs ^= rhs, Mathematica will set up transformation rules associated with each distinct symbol that occurs either as an argument of lhs, or as the head of an argument of lhs.

The transformation rules associated with a particular symbol s are always stored in a definite order, and are tested in that order when they are used. Each time you make an assignment, the corresponding transformation rule is inserted at the end of the list of transformation rules associated with s, except in the following cases:

• The left-hand side of the transformation rule is identical to a transformation rule that has already been stored, and any /; conditions on the right-hand side are also identical. In this case, the new transformation rule is inserted in place of the old one.
Mathematica determines that the new transformation rule is more specific than a rule already present, and would never be used if it were placed after this rule. In this case, the new rule is placed before the old one. Note that in many cases it is not possible to determine whether one rule is more specific than another; in such cases, the new rule is always inserted at the end.



Any questions about topics on this page? Click here to get an individual response.Buy NowMore Information
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.