Blank

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

Details

  • The head h in _h cannot itself contain pattern objects.

Background & Context

  • 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 _h) 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 p?test). For example, the code Cases[Range[100], _?(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.

Examples

Basic Examples  (2)

A pattern that matches any expression:

A pattern that matches any symbol:

A function definition that will take any single argument:

A function definition for integer arguments only:

Wolfram Research (1988), Blank, Wolfram Language function, https://reference.wolfram.com/language/ref/Blank.html.

Text

Wolfram Research (1988), Blank, Wolfram Language function, https://reference.wolfram.com/language/ref/Blank.html.

CMS

Wolfram Language. 1988. "Blank." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/Blank.html.

APA

Wolfram Language. (1988). Blank. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Blank.html

BibTeX

@misc{reference.wolfram_2023_blank, author="Wolfram Research", title="{Blank}", year="1988", howpublished="\url{https://reference.wolfram.com/language/ref/Blank.html}", note=[Accessed: 19-March-2024 ]}

BibLaTeX

@online{reference.wolfram_2023_blank, organization={Wolfram Research}, title={Blank}, year={1988}, url={https://reference.wolfram.com/language/ref/Blank.html}, note=[Accessed: 19-March-2024 ]}