Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Count the number of arguments a pure function or compiled function takes
ResourceFunction["ArgumentCount"][Function[…]] counts how many arguments the function takes. |
Find the highest numbered slot in a function:
| In[1]:= |
| Out[1]= |
| In[2]:= |
| Out[2]= |
| In[3]:= |
| Out[3]= |
In this function, slot 2 goes unused, but it will still be counted:
| In[4]:= |
| Out[4]= |
Slots in inner functions are not counted:
| In[5]:= | ![]() |
| Out[5]= |
A function that uses SlotSequence will be counted as taking infinitely many arguments:
| In[6]:= |
| Out[6]= |
String slots will be counted as being part of the first argument:
| In[7]:= |
| Out[7]= |
| In[8]:= |
| Out[8]= |
ArgumentCount works with compiled functions:
| In[9]:= |
| Out[9]= |
A function that uses SlotSequence will be counted as having infinite arguments:
| In[10]:= |
| Out[10]= |
This behavior can be changed with the "IgnoreSlotSequence" option:
| In[11]:= |
| Out[11]= |
This work is licensed under a Creative Commons Attribution 4.0 International License