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 allclose all

Basic Examples  (1)

Scope  (7)

Left-Hand Sides  (4)

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

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

The tag can appear as an argument of the left side:

The tag can appear as the head of an argument of the left side:

Different Kinds of Values  (3)

For ownvalues, the tag is redundant:

For downvalues, the tag is redundant:

Use a tag to define upvalues:

Applications  (1)

Implement modular arithmetic:

Properties & Relations  (7)

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

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

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:

Definitions with the same left side overwrite earlier ones:

Definition prints definitions associated with a symbol:

Information prints various information about a symbol, including any definitions:

UpValues returns a list of rules corresponding to any upvalues defined:

Use =. to clear definitions with a particular left-hand side:

Clear all definitions:

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

Immediate assignment does not introduce a scope:

Wolfram Research (1988), TagSetDelayed, Wolfram Language function, https://reference.wolfram.com/language/ref/TagSetDelayed.html.

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_2024_tagsetdelayed, author="Wolfram Research", title="{TagSetDelayed}", year="1988", howpublished="\url{https://reference.wolfram.com/language/ref/TagSetDelayed.html}", note=[Accessed: 03-December-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_tagsetdelayed, organization={Wolfram Research}, title={TagSetDelayed}, year={1988}, url={https://reference.wolfram.com/language/ref/TagSetDelayed.html}, note=[Accessed: 03-December-2024 ]}