Is there a way to force only selected values for function argument? For example for this function:
g[x_, y_, a_: ("b" || "c")] := Print[x, y, a]
force a to only get either values "b" or "c".
Is there a way to force only selected values for function argument? For example for this function:
g[x_, y_, a_: ("b" || "c")] := Print[x, y, a]
force a to only get either values "b" or "c".
Both answers of @kglr :
ClearAll[g]; g[x_, y_, a : "b" | "c"] := Print[x, y, a]
and @b.gates.you.know.what :
g[x_, y_, a_] /; MemberQ[{"b", "c"}, a] := Print[x, y, a]
worked.
g[x_, y_, a_] /; MemberQ[{"b", "c"}, a] := Print[x, y, a]. – b.gates.you.know.what Aug 18 '21 at 10:17ClearAll[g]; g[x_, y_, a : "b" | "c"] := Print[x, y, a]? – kglr Aug 18 '21 at 10:20