Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Set up a symbol to give an error message when called with an unexpected number of arguments
specifies that symbol is a function that takes exactly n arguments.
specifies that symbol takes between min and max arguments.
Declare that a symbol myFunc takes exactly two arguments:
When called with the correct number of arguments, the function behaves as normal:
Attempting to evaluate myFunc with the incorrect argument count throws an error message and does not evaluate:
DeclareArgumentCount does its work by defining a downvalue for the symbol in question:
The downvalue created by DeclareArgumentCount can be superseded by other downvalues in accordance with normal evaluation rules:
Now a two-argument call does not give a message despite having declared myFunc3 to take three arguments:
Wolfram Language 11.3 (March 2018) or above
This work is licensed under a Creative Commons Attribution 4.0 International License