WOLFRAM

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:

In[1]:=1

f evaluates when it is called with an integer:

In[2]:=2
Out[2]=2

f returns unevaluated when it is called with a noninteger:

In[3]:=3
Out[3]=3

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:

In[4]:=4

g evaluates when it is called with an odd integer:

In[5]:=5
Out[5]=5

g returns unevaluated when it is called with an even integer:

In[6]:=6
Out[6]=6