({{, lhs^:=rhs
assigns rhs to be the delayed value of lhs, and associates the assignment with symbols that occur at level one in lhs. }})

OpenersPrimaryExamplesSection(Spacer1)Examples  (13)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

f[g[x_]]^:=fg[x]

{f[g[2]],f[h[2]]}

OpenersExampleSection1(Spacer1)Scope  (6)

OpenersExampleSubsection0(Spacer1)Left-Hand Sides  (5)

An expression with a delayed definition is evaluated every time it is used:

rand[int]^:=Random[Integer]

Table[rand[int],{5}]

Make definitions for special and general cases using immediate and delayed assignments:

f[h[0]]^=h0;
f[h[x_]]^:=2f[h[x-1]]

f[h[10]]

The definition can be associated with a symbol appearing as an argument of the left side:

area[sq,s_]^:=s^2

area[sq,2]

The definition can be associated with the head of an argument of the left side:

area[sq[s_]]^:=s^2

area[sq[3]]

If several symbols appear in the left-hand side, upvalues for all of them are defined:

meth[g[x_],h[y_]]^:=fgh[x,y]

Definition[g]

Definition[h]

OpenersExampleSubsection1(Spacer1)Different Kinds of Values  (1)

^:= defines upvalues:

f[g[x_]]^:=f1[x]
f[h[x_]]:=f2[x]

{UpValues[g],DownValues[f]}

OpenersExampleSection2(Spacer1)Properties & Relations  (6)

^:= defines upvalues in the same way as using a tag does:

g/:f[g[x_]]:=f1[x]

f[h[x_]]^:=f2[x]

{UpValues[g],UpValues[h]}

A tag defines only one upvalue; ^:= makes definitions for all symbols:

g/:f1[g[x_],h[y_]]:=gh[x y]

f2[g[x_],h[y_]]^:=gh[x y]

{UpValues[g],UpValues[h]}

The right side of an immediate definition is evaluated when the definition is made:

rand[int]^=Random[Integer];

{rand[int],rand[int]}

The right side of a delayed definition is evaluated each time the definition is used:

rand[real]^:=Random[Real]

{rand[real],rand[real]}

Definitions with the same left side overwrite earlier ones:

f[h[x_]]^:=f1[x]

f[h[x_]]^:=f2[x]

Definition[h]

(RefLink[Definition, paclet:ref/Definition]) prints definitions associated with a symbol:

a_mod+b_mod^:=modPlus[a,b]

Definition[mod]

(RefLink[Information, paclet:ref/Information]) prints various information about a symbol, including any definitions:

?mod

(RefLink[UpValues, paclet:ref/UpValues]) returns a list of rules corresponding to any upvalues defined:

UpValues[mod]

Delayed assignment introduces a scope that is not affected by global variables:

x=5;

f[h[x_]]^:=x^2

{f[h[2]],x}

Immediate assignment does not introduce a scope:

g[h[x_]]^=x^2;

{g[h[2]],x}

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[UpSet, paclet:ref/UpSet])  ▪  (RefLink[TagSetDelayed, paclet:ref/TagSetDelayed])  ▪  (RefLink[SetDelayed, paclet:ref/SetDelayed])  ▪  (RefLink[Unset, paclet:ref/Unset])  ▪  (RefLink[ClearAll, paclet:ref/ClearAll])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[Associating Definitions with Different Symbols, paclet:tutorial/AssociatingDefinitionsWithDifferentSymbols])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Assignments, paclet:guide/Assignments])}})}})