# User Defined Functions Not Implementing HoldForm in list of Functions

When I insert the following code in Mathematica,

f[x__] := Map[HoldForm, {x}];
g[x_] := x^2;
f[g[t], Cos[t], Tan[t]]


I get {t^2, Cos[t], Tan[t]}, but I am trying to get {g[t], Cos[t], Tan[t]}. Why is HoldForm evaluating the user defined function g[t]? Any fix to this? Thank you.

The sample code has two evaluation leaks that need to be plugged.

The first is when the arguments are passed to f. f[x] evaluates x, and then f does its thing. The fix for this is to give f the HoldAll attribute.

The second is when the arguments are passed to Map. It's probably best to not change the attributes of Map, so instead we'll use Unevaluated to temporarily prevent evaluation until things get into f.

In[14]:= SetAttributes[f, HoldAll]
In[15]:= f[x__] := HoldForm /@ Unevaluated[{x}];
In[16]:= g[x_] := x^2;
In[17]:= InputForm[f[g[t], Cos[t], Tan[t]]]

Out[17]//InputForm= {HoldForm[g[t]], HoldForm[Cos[t]], HoldForm[Tan[t]]}

• Although this solves the problem in the example that I have provided, it doesn't fix the issue of the program that I am working with. The piecewise function that I had defined in replacement of g[t] always self-evaluates and I am not sure why. Aug 31 '16 at 5:50