DefaultValues

DefaultValues[f]

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

Details and Options

  • Transformation rules for Default[f] define the default for all positions. »
  • Transformation rules for Default[f,i] define the default for optional arguments in the i^(th) position of f. »
  • Transformation rules for Default[f,i,n] define the default for optional arguments in the i^(th) position of f when f is called with n arguments. »
  • You can specify the defaults for f by making an assignment of the form DefaultValues[f]=list.
  • The list returned by DefaultValues has elements of the form HoldPattern[lhs]:>rhs.
  • DefaultValues[f] only affects pattern matching and does not create any evaluation rules for f. »
  • Default values are not cleared by Clear. Use ClearAll to clear them. »

Examples

open allclose all

Basic Examples  (1)

Define a default argument for a function f:

These are the defaults associated with f:

Scope  (2)

DefaultValues returns rules corresponding to default arguments for a function:

DefaultValues 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 defaults to another symbol:

Properties & Relations  (8)

Assigning a value to Default[f] will define default arguments for all positions:

Assigning values to Default[f,i] will define default arguments for the i^(th) position:

Assigning values to Default[f,i,n] will define default arguments for the i^(th) position when f is called with n arguments:

DefaultValues[f] only affects pattern matching for f:

It does not on its own create any transformation rules for f[]:

Defaults can be defined by immediate or delayed assignments:

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

Without the HoldPattern, the left-hand side would have evaluated:

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

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

Use ClearAll to clear default values:

Clear does not clear them:

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

Text

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

CMS

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

APA

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

BibTeX

@misc{reference.wolfram_2021_defaultvalues, author="Wolfram Research", title="{DefaultValues}", year="1996", howpublished="\url{https://reference.wolfram.com/language/ref/DefaultValues.html}", note=[Accessed: 24-January-2022 ]}

BibLaTeX

@online{reference.wolfram_2021_defaultvalues, organization={Wolfram Research}, title={DefaultValues}, year={1996}, url={https://reference.wolfram.com/language/ref/DefaultValues.html}, note=[Accessed: 24-January-2022 ]}