global names in contexts

*To*: mathgroup at smc.vnet.net*Subject*: [mg6179] global names in contexts*From*: murray at math.umass.edu (Murray Eisenberg)*Date*: Thu, 27 Feb 1997 02:52:38 -0500*Sender*: owner-wri-mathgroup at wolfram.com

Within a context (created by a package), I need to evaluate a function from the Global` context. I thought Mathematica checks the current context and, if an object is not found there, searches the Global` context. But this is not so: f[x_] := x^2 BeginPackage["mine`"] f[7] (* value returned here is simply f[7], not 49 *) EndPackage[] I _could_ of course use BeginPackage["mine`", "Global`"], but unfortunately this would allow importation of _all_ Global` objects. Does that have some side effects that could lead to trouble? A related question: Suppose I change the package part above to: BeginPackage["mine`", "Global`"] f[x_] := x + 1 Global`f[7] (* result is LOCAL value 8 !! *) f[7] (* of course, value here is locally obtained 8 *) EndPackage[] Why does the Global`f[7] note give 49, the value at 7 of the global f? -- Murray Eisenberg Internet: murray at math.umass.edu Mathematics & Statistics Dept. Voice: 413-545-2859 (W) University of Massachusetts 413-549-1020 (H) Amherst, MA 01003 Fax: 413-545-1801