2

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".

Tigran
  • 51
  • 2

1 Answers1

2

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.

Tigran
  • 51
  • 2