Assuming your second example should give u , this should do the job:
ClearAll[arg]; SetAttributes[arg, HoldFirst]; arg[g_, n_] := Module[ {tmp, ret}, Unprotect[Part]; tmp = Attributes[Part]; SetAttributes[Part, HoldFirst]; ret = Part[g, n]; ClearAttributes[Part, HoldFirst]; SetAttributes[Part, tmp]; Protect[Part]; ret ]
so that
f[a_, b_] = a^2 + b^2.; arg[f[s, t], 1]
gives s .
This is very difficult, so I expect someone to find something better soon.
This is slightly better (does not override built-in functions even temporarily):
ClearAll[arg2]; SetAttributes[arg2, HoldFirst]; arg2[g_, n_] := Hold[g][[1, n]]
source share