This is documentation for Mathematica 4, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)

Pattern (:)Repeated (..)

Optional

FilledSmallSquarep:v is a pattern object which represents an expression of the form p, which, if omitted, should be replaced by v.

FilledSmallSquareOptional 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.

FilledSmallSquare 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.

FilledSmallSquare The form s_:v is equivalent to Optional[s_, v]. This form is also equivalent to s:_:v. There is no syntactic ambiguity since s must be a symbol in this case.

FilledSmallSquare The special form s_. is equivalent to Optional[s_] 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.

FilledSmallSquare Values for Default[f, ... ] specify default values to be used when _. appears as an argument of f. Any assignments for Default[f, ... ] must be made before _. first appears as an argument of f.

FilledSmallSquareOptional[s_h] represents a function which can be omitted, but which, if present, must have head h. There is no simpler syntactic form for this case.

FilledSmallSquare Functions with built-in default values include Plus, Times and Power.

FilledSmallSquare See The Mathematica Book: Section 2.3.9 and Section A.2.7.

FilledSmallSquare See also: Alternatives.

Pattern (:)Repeated (..)