Wolfram mathematica 将函数传递给模块而不指定其参数

Wolfram mathematica 将函数传递给模块而不指定其参数,wolfram-mathematica,Wolfram Mathematica,我想写一封信 Module Arg[f_,n_] 这需要一个函数f(假设第二个例子应该给出u,这应该可以完成以下工作: ClearAll[arg]; SetAttributes[arg, HoldFirst]; arg[g_, n_] := Module[ {tmp, ret}, Unprotect[Part]; tmp = Attributes[Part]; SetAttributes[Part, HoldFirst]; ret = Part[g, n]; Cle

我想写一封信

 Module Arg[f_,n_] 

这需要一个函数f(假设第二个例子应该给出
u
,这应该可以完成以下工作:

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
  ]
所以

f[a_, b_] = a^2 + b^2.;
arg[f[s, t], 1]
给出
s

这是非常沉重的虽然,所以我希望有人会找到更好的东西足够快

这稍微好一点(即使暂时也不会重新定义内置函数):

或许

SetAttributes[arg, HoldFirst];
arg[f_[x___], n_] := {x}[[n]]

f[a_, b_] := a^2 + b^2.
arg[f[arg[f[s, t], 1], t], 1]
arg[f[s, t], 2]

(*
 -> s
 -> t
*)

arg[ArcTan[f[Cos@Sin@x, x], t], 1]

(*
->  x^2. + Cos[Sin[x]]^2
*)

你意识到
Arg
是一个内部函数,对吗?你是想重写
Arg
(从定义上看不象)还是只是选择了一个糟糕的函数名?另外,你可能是指
Arg[f[u,v],2]
给出
v
?你刚才把我的编辑搞砸了@bel:)@yoda抱歉:(.我在浏览器上使用JS时遇到一些问题。也许这就是我没有收到“上次编辑”通知的原因。请随时回滚我的更改或将其与您的更改合并。@belisarius Nah,不用担心:)谢谢您的编辑和回答。
Arg[f_,n_] := Module[{}, ??? ]
 Arg[f_,a_,b_,n_]
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
  ]
f[a_, b_] = a^2 + b^2.;
arg[f[s, t], 1]
ClearAll[arg2];
SetAttributes[arg2, HoldFirst];
arg2[g_, n_] := Hold[g][[1, n]]
SetAttributes[arg, HoldFirst];
arg[f_[x___], n_] := {x}[[n]]

f[a_, b_] := a^2 + b^2.
arg[f[arg[f[s, t], 1], t], 1]
arg[f[s, t], 2]

(*
 -> s
 -> t
*)

arg[ArcTan[f[Cos@Sin@x, x], t], 1]

(*
->  x^2. + Cos[Sin[x]]^2
*)