Basic Examples

Find the highest numbered slot in a function:
In[]:=
[◼]
ArgumentCount
[Function[
2
#
]]
Out[]=
1
In[]:=
[◼]
ArgumentCount
[Function[#1+#2]]
Out[]=
2
In[]:=
[◼]
ArgumentCount
Function{x,y,z},Sinx+
y
z

Out[]=
3
In this function, slot 2 goes unused, but it will still be counted:
In[]:=
[◼]
ArgumentCount
[Function[#1+#3]]
Out[]=
3

Scope

Slots in inner functions will not be counted:
In[]:=
[◼]
ArgumentCount
[​​Function[​​Function[#1+#2+#3][#1,2#1,3#1]​​]​​]
Out[]=
1
A function that uses
SlotSequence
will be counted as having infinite arguments:
In[]:=
[◼]
ArgumentCount
[Function[Plus[##]]]
Out[]=
∞
String slots will be counted as being part of the first argument:
In[]:=
[◼]
ArgumentCount
[Function[#a+#b]]
Out[]=
1
In[]:=
[◼]
ArgumentCount
[Function[#a+#b+#2]]
Out[]=
2
ArgumentCount
works with compiled functions:
In[]:=
[◼]
ArgumentCount
[Compile[{x,y,z},Sqrt[xyz]]]
Out[]=
3

Options

IgnoreSlotSequence

A function that uses
SlotSequence
will be counted as having infinite arguments:
In[]:=
[◼]
ArgumentCount
[Function[Plus[#1,#2,##]]]
Out[]=
∞
This behavior can be changed with the
"IgnoreSlotSequence"
option:
In[]:=
[◼]
ArgumentCount
[Function[Plus[#1,#2,##]],"IgnoreSlotSequence"True]
Out[]=
2