Write a Function That Can Return Unevaluated
The result of evaluating a Wolfram Language function may be the same as the input if the function is called with the wrong types of arguments. You can replicate that behavior in user-defined functions.
Using Argument Patterns...
If you invoke a function with arguments that do not match the argument patterns in its definition, it will return unevaluated.
Define f to take an integer argument:
f[n_Integer] := {n, n}f evaluates when it is called with an integer:
f[9]f returns unevaluated when it is called with a noninteger:
f[1.2]Using Conditional Tests...
If you add a condition to a function definition, the function will return unevaluated if the condition is not satisfied.
Define g to evaluate only if its argument is odd:
g[n_] := {n, n} /; OddQ[n]g evaluates when it is called with an odd integer:
g[3]g returns unevaluated when it is called with an even integer:
g[4]