Condition 
范例
打开所有单元 关闭所有单元基本范例 (2)
范围 (2)
f[x_] := Module[{u}, u ^ 2 /; ((u = x - 1) > 0)]f[0]f[6]在函数体内部使用 Condition 以控制计算:
f[x_] := Module[{a}, a = Prime[10 ^ x];
(FactorInteger[a + 1]) /; a < 10 ^ 6]f[4]f[5]属性和关系 (2)
Condition 在模式的命名部分上运算布尔表达式:
Cases[{{a, b}, {1, 2, 3}, {{d, 6}, {d, 10}}}, {x_, y_} /; !ListQ[x] && !ListQ[y]]PatternTest 将检验函数应用于不需要名称的模式:
Cases[{{a, b}, {1, 2, 3}, {{d, 6}, {d, 10}}}, {_, _} ? VectorQ]Replace[{1, 7, "Hi", 3, z}, Except[x_ /; NumericQ[x]] :> 0, 1]可能存在的问题 (1)
Repeated[p /; test] 要求 p 中的每个命名模式在整个序列中都具有相同的值:
MatchQ[{3, 3, 3}, {(x_ /; IntegerQ[x / 3])..} ]MatchQ[{3, 6, 9}, {(x_ /; IntegerQ[x / 3])..} ]RepeatedNull 也是如此:
MatchQ[{3, 6, 9}, {(x_ /; IntegerQ[x / 3])...} ]将 PatternTest 与未命名的模式结合使用,以允许使用一系列不相同的元素:
MatchQ[{3, 6, 9}, {(_ ? (IntegerQ[# / 3]&))..} ]MatchQ[{3, 6, 9}, {(_ ? (IntegerQ[# / 3]&))...} ]相关的工作流程
- 编写一个以未计算形式返回的函数
历史
1988年引入 (1.0)
文本
Wolfram Research (1988),Condition,Wolfram 语言函数,https://reference.wolfram.com/language/ref/Condition.html.
CMS
Wolfram 语言. 1988. "Condition." Wolfram 语言与系统参考资料中心. Wolfram Research. https://reference.wolfram.com/language/ref/Condition.html.
APA
Wolfram 语言. (1988). Condition. Wolfram 语言与系统参考资料中心. 追溯自 https://reference.wolfram.com/language/ref/Condition.html 年
BibTeX
@misc{reference.wolfram_2026_condition, author="Wolfram Research", title="{Condition}", year="1988", howpublished="\url{https://reference.wolfram.com/language/ref/Condition.html}", note=[Accessed: 10-September-2026]}
BibLaTeX
@online{reference.wolfram_2026_condition, organization={Wolfram Research}, title={Condition}, year={1988}, url={https://reference.wolfram.com/language/ref/Condition.html}, note=[Accessed: 10-September-2026]}