f/:lhs=rhs
assigns rhs to be the value of lhs, and associates the assignment with the symbol f.
TagSet 
f/:lhs=rhs
assigns rhs to be the value of lhs, and associates the assignment with the symbol f.
Details
- TagSet 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, TagSet is treated as a scoping construct so that variables in nested occurrences are renamed if necessary.
Examples
open all close allBasic Examples (1)
Scope (3)
Different Kinds of Values (3)
For ownvalues, the tag is redundant:
x/:x = 7;
y = 7;{OwnValues[x], OwnValues[y]}For downvalues, the tag is redundant:
a/:a[zeta] = theta;
b[zeta] = theta;{DownValues[a], DownValues[b]}zeta/:a[zeta] = theta;
b[zeta] = theta;{UpValues[zeta], DownValues[b]}Applications (1)
Properties & Relations (5)
^= defines upvalues in the same way as using a tag does:
square/:area[square] = a ^ 2;
area[rectangle] ^= a * b;{UpValues[square], UpValues[rectangle]}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:
sq/:area[sq] = a ^ 2;sq/:area[sq] = s ^ 2;area[sq]Definition prints definitions associated with a symbol:
sq/:area[sq] = a ^ 2;Definition[sq]Information prints various information about a symbol, including any definitions:
? sqUpValues returns a list of rules corresponding to any upvalues defined:
UpValues[sq]Use =. to clear definitions with a particular left-hand side:
sq/:area[sq] = s ^ 2;
sq/:circ[sq] = 4s;sq/:circ[sq]=.{area[sq], circ[sq]}Clear[sq]Definition[sq]Possible Issues (2)
In the presence of global variables, pattern variables may show unexpected behavior:
x = 5;h/:f[h[x_]] = x ^ 2;f[h[2]]Delayed assignments behave as expected:
g/:f[g[x_]] := x ^ 2;f[g[2]]Use upvalues to assign to subscripted variables:
a/:Subscript[a, 1] = 5;FullForm[UpValues[a]]Subscripted variables are distinct from indexed variables:
a[1] = 6;FullForm[DownValues[a]]See Also
TagSetDelayed Set UpSet UpValues DownValues SubValues TagUnset
Tech Notes
Related Guides
History
Introduced in 1988 (1.0)
Text
Wolfram Research (1988), TagSet, Wolfram Language function, https://reference.wolfram.com/language/ref/TagSet.html.
CMS
Wolfram Language. 1988. "TagSet." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/TagSet.html.
APA
Wolfram Language. (1988). TagSet. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/TagSet.html
BibTeX
@misc{reference.wolfram_2026_tagset, author="Wolfram Research", title="{TagSet}", year="1988", howpublished="\url{https://reference.wolfram.com/language/ref/TagSet.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_tagset, organization={Wolfram Research}, title={TagSet}, year={1988}, url={https://reference.wolfram.com/language/ref/TagSet.html}, note=[Accessed: 13-June-2026]}