HoldPattern

HoldPattern[expr]

is equivalent to expr for pattern matching, but maintains expr in an unevaluated form.

Details

  • HoldPattern has attribute HoldAll.
  • The lefthand sides of rules are usually evaluated, as are parts of the lefthand sides of assignments. You can use HoldPattern to stop any part from being evaluated.

Examples

Basic Examples  (4)

Set up a pattern whose left-hand side is kept unevaluated:

Use the pattern:

Make a definition without the argument of f being evaluated:

Log[a,b] autoevaluates to Log[b]/Log[a], so there is a match:

Cases[e,patt->rhs] finds elements that match patt; use HoldPattern to find rules:

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

Text

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

BibTeX

@misc{reference.wolfram_2021_holdpattern, author="Wolfram Research", title="{HoldPattern}", year="1996", howpublished="\url{https://reference.wolfram.com/language/ref/HoldPattern.html}", note=[Accessed: 18-October-2021 ]}

BibLaTeX

@online{reference.wolfram_2021_holdpattern, organization={Wolfram Research}, title={HoldPattern}, year={1996}, url={https://reference.wolfram.com/language/ref/HoldPattern.html}, note=[Accessed: 18-October-2021 ]}

CMS

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

APA

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