I have defined a function fun[f_[x_,y_]]
. When I call it, I want to wrap everything by Unevaluated
:
fun[Unevaluated[f][Unevaluated[x], Unevaluated[y]]
But the above expression looks clumsy, especially if the arguments of fun
is more complicated. Is there a more elegant way to do it?
A simple example of the function fun
is as follows. The last line is what I expect to get.
fun[f_[x_, y_]] := ToExpression[ToString[f] <> ToString[x] <> ToString[y]]
f = 1; x = 1; y = 1;
fun[f[x, y]]
(* -> 111 *)
fun[Unevaluated[f][Unevaluated[x], Unevaluated[y]]
(* -> fxy *)
I tried several ways by using a single Unevaluated
or HoldPattern
, and they do not work.
fun
theHoldAll
attribute? $\endgroup$SetAttributes[fun, HoldAll]; fun[f_[x_, y_]] := Unevaluated[f][Unevaluated[x], Unevaluated[y]]; f = x = y = 1; fun[f[x, y]]
$\endgroup$