f/:lhs:=rhs
assigns rhs to be the delayed value of lhs, and associates the assignment with the symbol f.
TagSetDelayed 
f/:lhs:=rhs
assigns rhs to be the delayed value of lhs, and associates the assignment with the symbol f.
Details
- TagSetDelayed defines upvalues, downvalues or subvalues as appropriate.
- The symbol f in f/:lhs:=rhs must appear in lhs as the head of lhs, the head of the head, one of the elements of lhs or the head of one of the elements.
- A common case is f/:h[f[args]]:=rhs.
- You can see all the rules associated with a particular symbol by typing ?symbol.
- If f appears several times in lhs, then f/:lhs:=rhs associates the assignment with each occurrence.
- When it appears in unevaluated symbolic form, TagSetDelayed is treated as a scoping construct so that variables in nested occurrences are renamed if necessary.
Examples
open all close allBasic Examples (1)
g/:f[g[x_]] := fg[x]{f[g[2]], f[h[2]]}Scope (7)
Left-Hand Sides (4)
An expression with a delayed definition is evaluated every time it is used:
int/:rand[int] := RandomInteger[]Table[rand[int], {5}]Make definitions for special and general cases using immediate and delayed assignments:
h/:f[h[0]] = h0;
h/:f[h[x_]] := 2f[h[x - 1]]f[h[10]]The tag can appear as an argument of the left side:
sq/:area[sq, s_] := s ^ 2area[sq, 2]The tag can appear as the head of an argument of the left side:
sq/:area[sq[s_]] := s ^ 2area[sq[3]]Different Kinds of Values (3)
For ownvalues, the tag is redundant:
x/:x := RandomReal[]
y := RandomReal[]{OwnValues[x], OwnValues[y]}For downvalues, the tag is redundant:
f/:f[x_] := x ^ 2;
g[x_] := x ^ 2{DownValues[f], DownValues[g]}g/:f[g[x_]] := f1[x]
f[h[x_]] := f2[x]{UpValues[g], DownValues[f]}Applications (1)
Properties & Relations (7)
^:= 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:
int/:rand[int] = RandomInteger[];{rand[int], rand[int]}The right side of a delayed definition is evaluated each time the definition is used:
real/:rand[real] := RandomReal[]{rand[real], rand[real]}Definitions with the same left side overwrite earlier ones:
h/:f[h[x_]] := f1[x]h/:f[h[x_]] := f2[x]Definition[h]Definition prints definitions associated with a symbol:
mod/:a_mod + b_mod := modPlus[a, b]Definition[mod]Information prints various information about a symbol, including any definitions:
? modUpValues returns a list of rules corresponding to any upvalues defined:
UpValues[mod]Use =. to clear definitions with a particular left-hand side:
h/:f[h[x_]] := f1[x];
h/:g[h[x_]] := g1[x];h/:f[h[x_]]=.{f[h[1]], g[h[1]]}Clear[h]Definition[h]Delayed assignment introduces a scope that is not affected by global variables:
x = 5;h/:f[h[x_]] := x ^ 2{f[h[2]], x}Immediate assignment does not introduce a scope:
h/:g[h[x_]] = x ^ 2;{g[h[2]], x}Tech Notes
Related Guides
History
Introduced in 1988 (1.0)
Text
Wolfram Research (1988), TagSetDelayed, Wolfram Language function, https://reference.wolfram.com/language/ref/TagSetDelayed.html.
CMS
Wolfram Language. 1988. "TagSetDelayed." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/TagSetDelayed.html.
APA
Wolfram Language. (1988). TagSetDelayed. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/TagSetDelayed.html
BibTeX
@misc{reference.wolfram_2026_tagsetdelayed, author="Wolfram Research", title="{TagSetDelayed}", year="1988", howpublished="\url{https://reference.wolfram.com/language/ref/TagSetDelayed.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_tagsetdelayed, organization={Wolfram Research}, title={TagSetDelayed}, year={1988}, url={https://reference.wolfram.com/language/ref/TagSetDelayed.html}, note=[Accessed: 13-June-2026]}