SetDelayed (:=)

WMA link


SetDelayed[expr, value]

expr := value

assigns value to expr, without evaluating value.

SetDelayed is like Set, except it has attribute HoldAll, thus it does not evaluate the right-hand side immediately, but evaluates it when needed.

Changing the value of a affects x:

Condition (/;) can be used with SetDelayed to make an
assignment that only holds if a condition is satisfied:

It also works if the condition is set in the LHS:

We can use conditional delayed assignments to define symbols with values conditioned to the context. For example,

Set a to have a value of $3$ if certain variable b is positive. So, if this variable is not set, a stays unevaluated:

If now we assign a positive value to b, then a is evaluated:

Set
TagSet