HoldPattern
HoldPattern
doesn’t evaluateexpr
for pattern-matching.
Examples
One might be very surprised that the following line evaluates to True
!
When the line above is evaluated Times(p__)
evaluates to (p__)
before Symja checks to see if the pattern matches. MatchQ
then determines if And(x,y,z)
matches the pattern (p__)
and it does because And(x,y,z)
is itself a sequence of one.
Now the next line also evaluates to True
because both ( And(p__) )
and ( Times(p__) )
evaluate to ( p__ )
.
In the examples above prevent the patterns from evaluating, by wrapping them with HoldPattern
as in the following lines.
In the next lines HoldPattern
is used to ensure the head (And)
is changed to (List)
.
The two examples that follow have the same effect, but the use of HoldPattern
isn’t needed.
Related terms
Hold, HoldComplete, HoldForm, ReleaseHold, Unevaluated
Implementation status
- ✅ - full supported