Module[{x}, f@x_ = x; p@x_ := x; {x, x_, x_ -> x, x_ :> x} ] ?f ?p gives
{x$17312, x$17312_, x_ -> x, x_ :> x} f[x_]=x p[x_]:=x but I'd like to get
{x$17312, x$17312_, x$17312_ -> x$17312, x$17312_ :> x$17312} f[x$17312_]=x$17312 p[x$17312_]:=x$17312 I thought Module[{x}, body_] operates something like the following, which would do what I want:
module[{x_Symbol}, body_] := ReleaseHold[Hold@body /. x -> Unique@x]; SetAttributes[module, HoldAll]; module[{x}, f@x_ = x; p@x_ := x; {x, x_, x_ -> x, x_ :> x} ] ?f ?p I guess there are some cases with nested scoping constructs that need to be considered for special treatment, but why can't it do the replacement in Set, SetDelayed, Rule, RuleDelayed?
Motivation
I want to usef@x_ = Integrate[y^2, {y, 0, x}] instead of f@x_ := Evaluate@Integrate[y^2, {y, 0, x}] and to be safe I want to scope the variable/pattern label x to something unique.
See also Why does syntax highlighting in `Set` and `Rule` not color pattern names on the RHS?
f@x_ := Evaluate@Integrate[y^2, {y, 0, x}]case see this answer of mine. $\endgroup$