How to check if no argument is supplied to a function?
For example, if I have:
f[x_Integer]:=1
f[x_]:=Message[errm::err, x]
and I call f with no argument:
f[]
'nothing happens', I want to force a specific (error-)condition.
( Background: I am making MUnit tests for packages and OO-System classes. )
As an alternative to explicitly listing the zero-args possibility, you can do
f[x_Integer] := 1
f[args___] := (Message[errm::err, {args}];$Failed);
which would also catch the error cases of several passed arguments (assuming that it is an error).
This?
f[x_Integer] := 1
f[x_] := Message[errm::err, x]
f[] := Message[errm::err]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With