Advertisement
Guest User

Untitled

a guest
Jul 12th, 2014
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. tmp2 = x^2 + 1; f[y_] := Module[{x = 1}, Evaluate[y tmp2]]
  2.  
  3. tmp2 = x^2 + 1; Module[{x = 1}, Evaluate[tmp2]]
  4.  
  5. ClearAll[withRules]
  6. SetAttributes[withRules, HoldAll]
  7. withRules[rules_, expr_] :=
  8. Internal`InheritedBlock[{Rule, RuleDelayed},
  9. SetAttributes[{Rule, RuleDelayed}, HoldFirst];
  10. Unevaluated[expr] /. rules]
  11. ClearAll[f, tmp2]
  12. tmp2[y_] = y (x^2 + 1)
  13. withRules[{expr -> tmp2}, f[y_] := Module[{x = 1}, expr[y]]]
  14.  
  15. ClearAll[f, x];
  16. With[{tmp = tmp2},
  17. f[y_] := Module[{x = 1}, y tmp]]
  18.  
  19. ?f
  20. Global`f
  21. f[y$_]:=Module[{x$=1},y$ (1+x^2)]
  22.  
  23. ClearAll[f, x];
  24. Block[{tmp}, Unevaluated[f[y_] := Module[{x = 1}, y*tmp]] /. tmp -> tmp2]
  25.  
  26. SetAttributes[withTransforms,HoldAll];
  27. withTransforms[code_]:=
  28. Block[{kx=k*Sin[a]*Cos[b],ky=k*Sin[a]*Sin[b],kz=k*Cos[b]},
  29. code
  30. ]
  31.  
  32. withTransforms[Integrate[kx^2+ky^2,{a,0,2 Pi}]]
  33.  
  34. tmp2 = x^2 + 1;
  35.  
  36. With[{expr = tmp2},
  37. f[y_] := Module[{x = 1}, y expr]
  38. ]
  39.  
  40. ?f
  41.  
  42. Global`f
  43. f[y$_]:=Module[{x$=1},y$ (1+x^2)]
  44.  
  45. ClearAll[withRules]
  46. SetAttributes[withRules, HoldAll]
  47. withRules[rules_, expr_] :=
  48. PreemptProtect@Internal`InheritedBlock[
  49. {Rule, RuleDelayed},
  50. SetAttributes[{Rule, RuleDelayed}, HoldFirst];
  51. Unevaluated[expr] /. rules
  52. ]
  53.  
  54. Clear[f]
  55. withRules[{expr -> tmp2},
  56. f[y_] := Module[{x = 1}, y expr]
  57. ]
  58.  
  59. ?f
  60.  
  61. Global`f
  62. f[y_]:=Module[{x=1},y (1+x^2)]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement