New answers tagged


is there some way to take the call ReplaceAll[var, rules]and make it forget contexts for a minute? BeginPackage["Test`"]; replace::usage = "Returns var/.rules."; print; Begin["`Private`"]; replace[rules_] := ReplaceAll[Symbol[$Context <> "var"], rules] End[]; EndPackage[]; Not general, but works. I would expect that replace[rules_] := ...


You can make use of Formal Symbols. BeginPackage["Test`"]; replace::usage = "Returns \[FormalV]/.rules."; Begin["`Private`"]; replace[rules_] := \[FormalV] /.rules End[]; EndPackage[]; Then in the notebook. replace[\[FormalV] -> 0] (* 0 *) Hope this helps.


Try replace[rules_] := ReplaceAll[Global`var, rules] in your function. Then replace[var -> 0] replace[Test`Private`var -> 0] yields 0 var as I think you'd like.

Top 50 recent answers are included