This is documentation for Mathematica 8, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)


assigns rhs to be the delayed value of lhs. rhs is maintained in an unevaluated form. When lhs appears, it is replaced by rhs, evaluated afresh each time.
  • You can make assignments of the form , where test gives conditions for the applicability of each transformation rule. You can make several assignments with the same lhs but different forms of test.
  • returns Null if the assignment specified can be performed, and returns $Failed otherwise.
A variable defined with SetDelayed is evaluated every time it is used:
Make definitions for special and general cases using immediate and delayed assignments:
Make conditional definitions:
Define a function by several conditional cases:
Numerical values:
Define a procedure that computes a square root with Newton's method:
Perform a calculation on demand and cache the result:
Definitions for unevaluated expressions can implement call-by-name semantics:
The global variable has been modified:
The right side of an immediate definition is evaluated when the definition is made:
The right side of a delayed definition is evaluated each time the definition is used:
The arguments of the left side of a definition are evaluated before the definition is made:
Definitions with the same left side overwrite earlier ones:
The pattern variable is renamed if necessary inside a nested scope:
Delayed assignment introduces a scope that is not affected by global variables:
Immediate assignment does not introduce a scope:
Use a rule to do a transformation to a particular expression:
Use a definition to do a transformation automatically for all expressions involving :
More specific definitions are put in front of more general ones:
Definition prints definitions associated with a symbol:
Information prints various information about a symbol, including any definitions:
DownValues returns a list of rules corresponding to any downvalues defined:
Use Unset () to clear definitions with a particular left-hand side:
Clear any definitions, but not attributes:
Use ClearAll to clear attributes, too:
Omitting the defines a transformation only for a literal value, rather than a function:
Using delayed definitions may have unexpected consequences:
The definition actually made and its behavior:
Use Evaluate to force evaluation of the right-hand side:
Or use Set to force evaluation of the right-hand side:
An iterative runaway definition:
By providing a base case, the iteration terminates:
A recursive runaway definition:
By providing a base case, the recursion terminates:
Dynamic programming for the Fibonacci sequence:
New definitions have been added during the calculation:
New in 1