Hot answers tagged

3

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_] := ...


3

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.


2

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.



Only top voted, non community-wiki answers of a minimum length are eligible