Default[f]
gives the default value for arguments of the function f obtained with a _. pattern object.
Default[f,i]
gives the default value to use when _. appears as the i
argument of f.
Default[f,i,n]
gives the default value for the i
argument out of a total of n arguments.
Default[f,…]=val
defines default values for arguments of f.
Default
Default[f]
gives the default value for arguments of the function f obtained with a _. pattern object.
Default[f,i]
gives the default value to use when _. appears as the i
argument of f.
Default[f,i,n]
gives the default value for the i
argument out of a total of n arguments.
Default[f,…]=val
defines default values for arguments of f.
Details
- _. represents an optional argument to a function, with a default value specified by Default.
- The necessary values for Default[f] must always be defined before _. is used as an argument of f.
- Values defined for Default[f,…] are stored with values of Options[f] in DefaultValues[f].
- Default values only affect pattern matching and do not create any evaluation rules for f.
Examples
open all close allBasic Examples (2)
Define 0 to be the default argument for a function f:
Default[f] = 0_. represents an argument that can be omitted:
f[x_., y_.] = {x, y}If the second argument is omitted, the default value of 0 is used instead:
f[a]If both arguments are omitted, both are taken to have the default value 0:
f[]Define default values for the first and second arguments:
Default[f, 1] = 1;
Default[f, 2] = 2;If an argument is omitted, the corresponding default value is used:
Replace[f[], f[x_., y_.] :> {x, y}]Scope (1)
Define 2 to be the default argument for the pattern f[_.,_]:
Default[f, 1, 2] = 2;Define 3 to be the default argument for the pattern f[_.,_,_]:
Default[f, 1, 3] = 3;With a two-argument pattern, the default value of 2 is used for the omitted argument:
Replace[f[y], f[x_., y_] :> {x, y}]With a three-argument pattern, the default value of 3 is used for the omitted argument instead:
Replace[f[y, z], f[x_., y_, z_] :> {x, y, z}]Properties & Relations (4)
Assigning a value to Default[f] will define default arguments for all positions:
Default[f] = 0Replace[f[], f[x_., y_.] :> {x, y}]Assigning a value to Default[f] only affects pattern matching for f:
f[x_Integer] := xMatchQ[f[], f[_.]]Default[f] = 0MatchQ[f[], f[_.]]It does not on its own create any transformation rules for f[…]:
{f[], f[0]}Use a pattern involving Optional in the definition of f to create a default evaluation:
f[Optional[x_Integer]] := xf[]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]}Use ClearAll to clear default values:
Default[f] = Default[g] = 0ClearAll[f];
DefaultValues[f]Clear does not clear them:
Clear[g];
DefaultValues[g]See Also
Tech Notes
Related Guides
-
▪
- Patterns
History
Introduced in 1988 (1.0)
Text
Wolfram Research (1988), Default, Wolfram Language function, https://reference.wolfram.com/language/ref/Default.html.
CMS
Wolfram Language. 1988. "Default." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/Default.html.
APA
Wolfram Language. (1988). Default. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Default.html
BibTeX
@misc{reference.wolfram_2026_default, author="Wolfram Research", title="{Default}", year="1988", howpublished="\url{https://reference.wolfram.com/language/ref/Default.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_default, organization={Wolfram Research}, title={Default}, year={1988}, url={https://reference.wolfram.com/language/ref/Default.html}, note=[Accessed: 12-June-2026]}