HoldPattern
Usage
• HoldPattern[expr]对模式匹配等价于expr, 但保持expr在不计算形式。
Notes
• HoldPattern 有属性 HoldAll.
• 规则的左边通常被计算,如同是任务的左边的部分。可以使用HoldPattern中止任何正被计算的部分。 • 例如: expr /. HoldPattern[Integrate[y_, x_]] -> rhs 变换在expr中Integrate[y_, x_] 形式的任何子表达式。
没有HoldPattern, 规则中的Integrate[y_, x_]立即被计算给出x_ y_ ,且替换并不有效。 • 例如: f[HoldPattern[Integrate[y_, x_]]] := value 能被用于f[Integrate[y_, x_]]形式的表达式的分配。没有HoldPattern, 函数Integrate在分配时被计算。 • 参见 Mathematica 全书 : 节 2.5.6.
Further Examples
Patterns are not considered to be special outside the context of the pattern matcher.
In[1]:=
|
Out[1]=
|
For instance, arithmetic operations work on patterns in the same way as on any other symbolic entity.
In[2]:=
|
Out[2]=
|
Use HoldPattern when you want to control the evaluation of patterns.
In[3]:=
|
Out[3]=
|
|