2
$\begingroup$

Is it possible in Mathematica to have function recognize its name? Say FunFunction[blah blah blah

];

Is there a way, while still inside the function, for the function to recognize its own name?

$\endgroup$
6
  • $\begingroup$ As far as I know, no. You could determine it at runtime via Stack maybe. $\endgroup$
    – b3m2a1
    Commented Apr 2, 2019 at 20:25
  • $\begingroup$ A fuller example would be helpful, as there is more than one kind of function in Mathematica. For instance, if you are writing the function yourself, you could simply type it yourself: f[x_] := (Print["My name is ", f]; x^2) $\endgroup$
    – Michael E2
    Commented Apr 2, 2019 at 20:31
  • 2
    $\begingroup$ One could write the function call : f[x_] := (Print["Hi! You called ", HoldForm[call]]; x^2) and then f[4]. $\endgroup$
    – Michael E2
    Commented Apr 2, 2019 at 20:33
  • 2
    $\begingroup$ @tombom21 while answers in the linked topic suggest 'not without trickery' I believe it is a duplicate. Let me know if you disagree. $\endgroup$
    – Kuba
    Commented Apr 2, 2019 at 20:36
  • 1
    $\begingroup$ You might want to see this too. $\endgroup$ Commented Apr 2, 2019 at 23:17

0

Browse other questions tagged or ask your own question.