MathGroup Archive 1997

[Date Index] [Thread Index] [Author Index]

Search the Archive

global names in contexts

  • To: mathgroup at
  • Subject: [mg6179] global names in contexts
  • From: murray at (Murray Eisenberg)
  • Date: Thu, 27 Feb 1997 02:52:38 -0500
  • Sender: owner-wri-mathgroup at

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


f[7]    (* value returned here is simply f[7], not 49 *)


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 *)

Why does the Global`f[7] note give 49, the value at 7 of the global f?

  Murray Eisenberg                       Internet:  murray at
  Mathematics & Statistics Dept.            Voice:  413-545-2859 (W)
  University of Massachusetts                       413-549-1020 (H)
  Amherst, MA 01003                           Fax:  413-545-1801

  • Prev by Date: Re: barfing on an integral
  • Next by Date: Re: selecting from lists
  • Previous by thread: Integration Package
  • Next by thread: names, symbols, and contexts