Mathematica Asked on March 21, 2021
Suppose I have a function
f[x_,y___]:=
(code)
and I want my code to check whether the parameter y
is omitted. What’s the easiest way to do this?
I tried some quick guesses, like If[y == Null]
and If[¬ValueQ@y]
, but these didn’t work. I was able to use
f[x_,y___]:=
Module[{yList},
yList={y};
If[yList == {},(* code *)]
]
but surely there is a more elegant method than this clunky one.
The easy way is to use two different patterns:
f[x_]:= single arg code
f[x_,y__]:= double arg code
Correct answer by John Doty on March 21, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP