gives a list of transformation rules corresponding to default values of f.
DefaultValues["symbol"]
gives a list of transformation rules corresponding to all default values defined for the symbol named "symbol" if it exists.
DefaultValues
gives a list of transformation rules corresponding to default values of f.
DefaultValues["symbol"]
gives a list of transformation rules corresponding to all default values defined for the symbol named "symbol" if it exists.
Details and Options
- DefaultValues[f] gives rules corresponding to default positional arguments as well as the default options of f.
- 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
position of f. » - Transformation rules for Default[f,i,n] define the default for optional arguments in the i
position of f when f is called with n arguments. » - Transformation rules for Options[f] define the default options of f. »
- 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 all close allBasic Examples (1)
Scope (3)
DefaultValues returns rules corresponding to default arguments for a function:
Default[f] = 0;DefaultValues[f]Default[f1] = 1;Default[f2] = 3;Default[g] = 5;Obtain the default values of symbols whose names start with f:
DefaultValues /@ Names["f*"]DefaultValues can be used to set the values directly:
DefaultValues[f] = {HoldPattern[Default[f, 2]] :> 1, HoldPattern[Default[f, _]] :> 0};Definition[f]f[x_., y_., z_.] := {x, y, z}f[]Applications (2)
The resulting rules are in the order given:
Default[f, n_ /; n > 1] := x
Default[f, n_ /; n < 3] := yDefaultValues[f]f[a_., b_., c_., d_.] := g[a, b, c, d]f[]DefaultValues[f] = Reverse[DefaultValues[f]]f[a_., b_., c_., d_.] := g[a, b, c, d]f[]Copy a symbol's defaults to another symbol:
Default[f] = 0;DefaultValues[g] = DefaultValues[f] /. f -> gg[x_.] := xg[]Properties & Relations (10)
Assigning a value to Default[f] will define default arguments for all positions:
Default[f] = 0DefaultValues[f]f[x_., y_.] := {x, y}f[]Assigning values to Default[f,i] will define default arguments for the i
position:
Default[f, 1] = 1;
Default[f, 2] = 2;DefaultValues[f]f[x_., y_.] := {x, y}f[]Assigning values to Default[f,i,n] will define default arguments for the i
position when f is called with n arguments:
Default[f, 1, 3] = 3;
Default[f, 1, 2] = 2;DefaultValues[f]f[x_., y_, z_] := {x, y, z}
f[x_., y_] := {x, y}f[y, z]f[y]Assigning values to Options[f] will define default options:
Options[f] = {opt1 -> def1, opt2 -> def2};DefaultValues[f]OptionValue[f, opt1]OptionValue[f, opt2]DefaultValues[f] only affects pattern matching for f:
DefaultValues[f] = {HoldPattern[Default[f]] :> 0}Replace[f[], f[x_.] :> x]It does not on its own create any transformation rules for f[…]:
f[]Defaults can be defined by immediate or delayed assignments:
Default[f] = 0;
Default[g, n_] := n ^ 2;f[a_, b_, c_.] := c
g[a_, b_, c_.] := c{f[a, b], g[a, b]}HoldPattern is used to protect the rules from their own definitions:
Default[f] = 0;DefaultValues[f]Without the HoldPattern, the left-hand side would have evaluated:
Default[f] :> 0DefaultValues["sym"] will issue a message if the specified symbol does not exist:
DefaultValues["f"]If the symbol exists but has no definitions, an empty list is returned:
f;
DefaultValues["f"]Definition and Information display defaults but do not return them as values:
Default[f] = 0;Definition[f]%//FullFormDefaultValues returns a value that can be used in a program:
DefaultValues[f]Use ClearAll to clear default values:
Default[f] = Default[g] = 0ClearAll[f];
DefaultValues[f]Clear does not clear them:
Clear[g];
DefaultValues[g]Related Guides
History
Introduced in 1991 (2.0) | Updated in 1996 (3.0) ▪ 2022 (13.2)
Text
Wolfram Research (1991), DefaultValues, Wolfram Language function, https://reference.wolfram.com/language/ref/DefaultValues.html (updated 2022).
CMS
Wolfram Language. 1991. "DefaultValues." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2022. 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_2026_defaultvalues, author="Wolfram Research", title="{DefaultValues}", year="2022", howpublished="\url{https://reference.wolfram.com/language/ref/DefaultValues.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_defaultvalues, organization={Wolfram Research}, title={DefaultValues}, year={2022}, url={https://reference.wolfram.com/language/ref/DefaultValues.html}, note=[Accessed: 13-June-2026]}