# Feeding a mathematical function as the argument of a Function

I have the following Function:

Testing[g[x_], y_] := Module[{s = x, t = y, c }, c = s + t ; c]


Which I am just trying to get to work before doing my actual application. It should accept a function g[x] and do stuff with it.

As a test, I try:

f[x_] := x^2;
Testing[f[x], 4]


But it just returns

Testing[x^2, 4]

which means that it does not understand what I mean...? What is the correct syntax to feed a mathematical function into my Function?

• Testing will only work for something with head g while f[x] evaluates to Power[x,2]. – Kuba Nov 23 '16 at 16:02
• Why not just run Testing[x_, y_]? – Feyre Nov 23 '16 at 16:09
• If you want it to accept a function in the form g[x], but with any kind of name (instead of g specifically) and any kind of variable, then you should use Testing[g_[x_], y_] := .... Moreover, you should probably make Testing HoldFirst to keep the function from evaluating too early: SetAttributes[Testing, HoldFirst] – Sjoerd Smit Nov 23 '16 at 16:34

As I understand you, what you want is that c becomes x^2 + 4. This gives you that polynomial with an anonymous variable instead of x:
Testing[g_, y_] := Module[{s = g[#], t = y, c}, c = Evaluate[s + t] &; c]