ArgumentCountQ
Usage Message: ArgumentCountQ[head,len,min,max] tests whether the number len of arguments of a function head is
between min and max. Attributes[ArgumentCountQ] = {Protected, ReadProtected} Related
Symbols: Message
Notes: ArgumentCountQ[head, len, min, max] returns True if len is between min and max (if min <= len <= max is True), False if len is not between min and max, and does nothing if min is not less than max. When ArgumentCountQ returns False, it generates a message that indicates the expected number of arguments.
In[1]:= ArgumentCountQ[h, 3, 2, 5]
Out[1]= True
In[2]:= ArgumentCountQ[h, 6, 2, 5]
h::argb: h called with 6 arguments; between 2 and 5 arguments are expected.
Out[2]= False
In[3]:= ArgumentCountQ[h, 6, 5, 2]
Out[3]= ArgumentCountQ[h, 6, 5, 2]
ArgumentCountQ is intended for use in argument checking in packages written in the Mathematica programming language. For example, if you define a function that should be used only with three arguments, you can use ArgumentCountQ to take care of checking the number of arguments and generating a message if necessary.
In[4]:= f[p___] := Thread[{e1, e2, e3} -> {p}] /;
ArgumentCountQ[f, Length[{p}], 3, 3]
In[5]:= f[x, y, z]
Out[5]= {e1 -> x, e2 -> y, e3 -> z}
In[6]:= f[w, x, y, z]
f::argrx: f called with 4 arguments; 3 arguments are expected.
Out[6]= f[w, x, y, z]
ArgumentCountQ is defined in the startup package ArgumentCount.m. Detailed questions about its behavior can normally be resolved by looking at the code in that package.
Questions or comments? Send email to support@wolfram.com.
| |