UpValues

UpValues[f]

gives a list of transformation rules corresponding to all upvalues (values for g[,f[],]) defined for the symbol f.

UpValues["symbol"]

gives a list of transformation rules corresponding to all upvalues defined for the symbol named "symbol" if it exists.

Details and Options

  • UpValues[f] also gives rules corresponding to g[,f,].
  • When evaluating an expression, matching upvalues are applied before matching downvalues. »
  • If a function has attribute HoldAllComplete, no upvalues are applied prior to entering the body of the function. »
  • UpValues are typically defined using UpSet, UpSetDelayed, TagSet or TagSetDelayed.
  • You can specify the upvalues for f by making an assignment of the form UpValues[f]=list.
  • The list returned by UpValues has elements of the form HoldPattern[lhs]:>rhs.

Examples

open allclose all

Basic Examples  (1)

Define an upvalue for a symbol g using TagSetDelayed:

Define an upvalue using UpSetDelayed:

These are the upvalues associated with g:

Scope  (3)

UpValues returns rules corresponding to upvalues defined for a symbol:

Create several values:

Obtain the upvalues of symbols whose names start with x:

UpValues can be used to set the values directly:

Applications  (2)

The resulting rules are in the order given:

Now reorder the definitions:

Copy a symbol's definitions to another symbol:

Properties & Relations  (7)

Values can be defined by immediate or delayed assignments:

HoldPattern is used to protect the rules from their own definitions:

UpValues["sym"] will issue a message if the specified symbol does not exist:

If the symbol exists but has no definitions, an empty list is returned:

Definition and Information display upvalues but do not return them as values:

UpValues returns a value that can be used in a program:

Evaluation of an expression involves applying matching upvalues:

Matching upvalues are used before matching downvalues in evaluation:

The upvalue for g is used prior to the downvalue for f:

Compare with a manual application of the upvalue and downvalue:

Define an upvalue for g that applies for all heads:

Even if a function has attribute HoldAll, the upvalue will be applied during evaluation:

If a function has attribute HoldAllComplete, the upvalue will not be applied:

Wolfram Research (1991), UpValues, Wolfram Language function, https://reference.wolfram.com/language/ref/UpValues.html (updated 1996).

Text

Wolfram Research (1991), UpValues, Wolfram Language function, https://reference.wolfram.com/language/ref/UpValues.html (updated 1996).

CMS

Wolfram Language. 1991. "UpValues." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 1996. https://reference.wolfram.com/language/ref/UpValues.html.

APA

Wolfram Language. (1991). UpValues. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/UpValues.html

BibTeX

@misc{reference.wolfram_2024_upvalues, author="Wolfram Research", title="{UpValues}", year="1996", howpublished="\url{https://reference.wolfram.com/language/ref/UpValues.html}", note=[Accessed: 22-November-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_upvalues, organization={Wolfram Research}, title={UpValues}, year={1996}, url={https://reference.wolfram.com/language/ref/UpValues.html}, note=[Accessed: 22-November-2024 ]}