I would like to know the name of the current function from within that function. For example, consider the following code
myFunction[args___] :=
Module[{},
checkArgs[args,"myFunction"];
someCode[]
];
where checkArgs is used in several functions which have the same types of arguments and reports an error message which includes the name of the function it was called from. I would like to call checkArgs without having to give it the name of the function.
The evaluation stack, obtained using Stack, I believe does not contain this information unless called from within a StackComplete, and this is generally not the case in normal use of the function.
I appreciate that "the current function" is not necessarily a well-defined concept in Mathematica, since you can have nested function definitions, and a function is just a rule definition anyway. However, the options management system uses this concept. If I have OptionsPattern in the function definition, I can call OptionValue[x], and something knows to look in Options[myFunction] to find the information about the options. So could whatever this mechanism is using be accessed? Is there a way to get the current function from the options system?
The best solution I have come up with is this:
(fn:myFunction)[args___] :=
Module[{},
checkArgs[args,fn];
someCode[]
];
which avoids having to pass in the function name explicitly, but is still quite ugly.
