How can we check if an entry to our function is a Function or a Pure Function?
For example:
FunctionQ[target_]:=...
FunctionQ[Function[x, x^2]] == True
FunctionQ[#^2&] == True
FunctionQ[x^2] == False
It looks like we don't have a FunctionQ method available on Mathematica.
The motivation is that I'd like to combine this with the answer of this question to create only one function for the accepted answer of that link.
Edit:
Combining the provided answer, it looks like we can do the following:
FunctionQ[expression_Function?System`Private`ValidQ] := True;
FunctionQ[___] := False;
Test[expression_, variable_Symbol] :=
Block[
{final},
If[
FunctionQ[expression],
final = expression,
final = Function[variable, expression]
]
][4];
Test[Function[x, x^2], x] (* 1 *)
Test[#^2 &, x] (* 2 *)
Test[x^2, x] (* 3 *)
f1 = x^2; Test[f1, x] (* 4 *)
f2[x_] := x^2; Test[f2, x] (* 5 *)
Test[f2[x], x] (* 6 *)
16 (* 1 *)
16 (* 2 *)
16 (* 3 *)
16 (* 4 *)
b (* 5 *)
16 (* 6 *)
FunctionQ[Log]returnTrue? How aboutFunctionQ[Derivative[1][Zeta]]orFunctionQ[Hold]? – J. M.'s missing motivation Jun 07 '20 at 15:38HeadofFunction) you can use a pattern likef[z_Function] := .... Thenf[(#^2&)]orf[Function[{x},x^2]]would evaluate. – Bob Hanlon Jun 07 '20 at 15:54function. check type for function it is useful for parsing input for example. Mathematica should really have FunctionQ as well. – Nasser Jun 08 '20 at 06:56