v is a pattern object which represents an expression of the form p, which, if omitted, should be replaced by v.
Optional is used to specify "optional arguments" in functions represented by patterns. The pattern object p gives the form the argument should have, if it is present. The expression v gives the "default value" to use if the argument is absent.
Example: the pattern f[x_,
y_:1] is matched by f[a], with x taking the value a, and y taking the value 1. It can also be matched by f[a,
b], with y taking the value b.
The form s
v is equivalent to Optional[
]. This form is also equivalent to s
v. There is no syntactic ambiguity since s must be a symbol in this case.
The special form s
_. is equivalent to Optional[
_] and can be used to represent function arguments which, if omitted, should be replaced by default values globally specified for the functions in which they occur.
Values for Default[
, ... ] specify default values to be used when _. appears as an argument of f. Any assignments for Default[
, ... ] must be made before
_. first appears as an argument of f.
] represents a function which can be omitted, but which, if present, must have head h. There is no simpler syntactic form for this case.
Functions with built-in default values include Plus, Times and Power.
See the Mathematica book: Section 2.3.9, Section A.2.7.
See also: Alternatives.
This function converts a list of integers to a base representation. It uses the optional pattern object base_:2 to indicate that the base of the input is assumed to be unless indicated otherwise.
This gives the digits of the number in base .
Now this list can be converted back to base .
If the list of digits was in some other base, you would have to indicate that explicitly in the convert function. Here is a list of the base digits of the number .
Now you have to provide the correct base to the convert function.