Skip to main content
replaced http://mathematica.stackexchange.com/ with https://mathematica.stackexchange.com/
Source Link
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?Why does syntax highlighting in `Set` and `Rule` not color pattern names on the RHS?

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?

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?

edited tags
Link
Karsten7
  • 27.6k
  • 5
  • 74
  • 135
added 135 characters in body
Source Link
masterxilo
  • 5.8k
  • 19
  • 39
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?

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

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?

Tweeted twitter.com/StackMma/status/749516095426555905
Source Link
masterxilo
  • 5.8k
  • 19
  • 39
Loading