1
$\begingroup$

Is there any way to match all functions? There's an existing answer for matching functions of one parameter (_@_) but it doesn't work for trying to test if a symbol is a function.

Does testing if a symbol has any downvalues work? Downvalue checking does not work. I would like to match all of the following:

f, in f=(#)&

f, in f[x_]=x

(#)& itself.

$\endgroup$
13
  • $\begingroup$ _Function matches a pure function, is this what you want? $\endgroup$
    – C. E.
    Apr 2, 2016 at 2:49
  • $\begingroup$ Mm, it seems not, because for some reason Mathematica doesn't implement functions the way it does everything else, with substitutions. Evaluating a function name just gives you the function name, not the function body. >.< $\endgroup$ Apr 2, 2016 at 3:18
  • $\begingroup$ When you say "pure functions", do you mean objects that have Function as the Head, or do you mean f in, say f[x_] := x^2? Because MatchQ[#&, _Function] returns True. $\endgroup$
    – march
    Apr 2, 2016 at 3:56
  • 1
    $\begingroup$ I'm still confused. If f = # &, then both MatchQ[f, _Function] and MatchQ[#&, _Function] evaluate to True. Perhaps you should explain your use case and give a couple of examples in your post. $\endgroup$
    – march
    Apr 2, 2016 at 4:14
  • 4
    $\begingroup$ This looks like you're doing too much work for your problem. Consider explaining your actual problem that led you to consider this. $\endgroup$ Apr 2, 2016 at 8:32

0

Browse other questions tagged or ask your own question.