Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- tmp2 = x^2 + 1; f[y_] := Module[{x = 1}, Evaluate[y tmp2]]
- tmp2 = x^2 + 1; Module[{x = 1}, Evaluate[tmp2]]
- ClearAll[withRules]
- SetAttributes[withRules, HoldAll]
- withRules[rules_, expr_] :=
- Internal`InheritedBlock[{Rule, RuleDelayed},
- SetAttributes[{Rule, RuleDelayed}, HoldFirst];
- Unevaluated[expr] /. rules]
- ClearAll[f, tmp2]
- tmp2[y_] = y (x^2 + 1)
- withRules[{expr -> tmp2}, f[y_] := Module[{x = 1}, expr[y]]]
- ClearAll[f, x];
- With[{tmp = tmp2},
- f[y_] := Module[{x = 1}, y tmp]]
- ?f
- Global`f
- f[y$_]:=Module[{x$=1},y$ (1+x^2)]
- ClearAll[f, x];
- Block[{tmp}, Unevaluated[f[y_] := Module[{x = 1}, y*tmp]] /. tmp -> tmp2]
- SetAttributes[withTransforms,HoldAll];
- withTransforms[code_]:=
- Block[{kx=k*Sin[a]*Cos[b],ky=k*Sin[a]*Sin[b],kz=k*Cos[b]},
- code
- ]
- withTransforms[Integrate[kx^2+ky^2,{a,0,2 Pi}]]
- tmp2 = x^2 + 1;
- With[{expr = tmp2},
- f[y_] := Module[{x = 1}, y expr]
- ]
- ?f
- Global`f
- f[y$_]:=Module[{x$=1},y$ (1+x^2)]
- ClearAll[withRules]
- SetAttributes[withRules, HoldAll]
- withRules[rules_, expr_] :=
- PreemptProtect@Internal`InheritedBlock[
- {Rule, RuleDelayed},
- SetAttributes[{Rule, RuleDelayed}, HoldFirst];
- Unevaluated[expr] /. rules
- ]
- Clear[f]
- withRules[{expr -> tmp2},
- f[y_] := Module[{x = 1}, y expr]
- ]
- ?f
- Global`f
- f[y_]:=Module[{x=1},y (1+x^2)]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement