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]&))...} ]テクニカルノート
-
▪
- パターン適用範囲の制限 ▪
- 条件子 ▪
- 文字列パターン
関連するガイド
-
▪
- パターン ▪
- 言語の概要 ▪
- 条件文 ▪
- ロバスト性とエラー処理 ▪
- Wolfram言語のシンタックス ▪
- 規則とパターン
関連するワークフロー
- 結果を未評価で返す関数を書く
履歴
1988 で導入 (1.0)
テキスト
Wolfram Research (1988), Condition, Wolfram言語関数, https://reference.wolfram.com/language/ref/Condition.html.
CMS
Wolfram Language. 1988. "Condition." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/Condition.html.
APA
Wolfram Language. (1988). Condition. Wolfram Language & System Documentation Center. Retrieved from 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-August-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-August-2026]}