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 allclose allBasic Examples (2)
Define 0 to be the default argument for a function f:
_. represents an argument that can be omitted:
If the second argument is omitted, the default value of 0 is used instead:
If both arguments are omitted, both are taken to have the default value 0:
Define default values for the first and second arguments:
If an argument is omitted, the corresponding default value is used:
Scope (1)
Define 2 to be the default argument for the pattern f[_.,_]:
Define 3 to be the default argument for the pattern f[_.,_,_]:
With a two-argument pattern, the default value of 2 is used for the omitted argument:
With a three-argument pattern, the default value of 3 is used for the omitted argument instead:
Properties & Relations (4)
Assigning a value to Default[f] will define default arguments for all positions:
Assigning a value to Default[f] only affects pattern matching for f:
It does not on its own create any transformation rules for f[…]:
Use a pattern involving Optional in the definition of f to create a default evaluation:
Defaults can be defined by immediate or delayed assignments:
Use ClearAll to clear default values:
Clear does not clear them:
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