_ or Blank
is a pattern object that can stand for any Wolfram Language expression.
_h or Blank[h]
can stand for any expression with head h.
- Blank is a pattern object that can stand for any expression in the Wolfram Language. The expression Blank may be compactly denoted with the underscore character _. The more specific pattern Blank[h] (compactly denoted ) stands for any expression with head h. Blank is an extremely powerful and useful construct for pattern-based programming and is the foundation upon which pattern-matching functionality is built. The most common function taking Blank and related patterns as arguments is SetDelayed. Other such functions include MatchQ, Cases, DeleteCases, Count, and RuleDelayed.
- Sequences of one or more blanks are represented using the pattern object BlankSequence (double underscore: __). Sequences of zero or more blanks are represented using the pattern object BlankNullSequence (triple underscore: ___). In general, patterns involving multiple instances of Blank are faster to work with than those involving BlankSequence and BlankNullSequence, since vastly more possibilities must be tested for a possible match in the latter two cases.
- Blank may be used together with Optional to specify a pattern object for an expression which, if omitted, is replaced by a default value. The Alternatives pattern object allows specification of several possible patterns, including Blank. Blank may be combined with a PatternTest (written in shorthand as ). For example, the code Cases[Range, _?(IntegerQ[Sqrt[#]] &)]] (which makes use of a pure function with a Slot specification) selects and returns the list of all square numbers less than or equal to 100.
Introduced in 1988