Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1997
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1997

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

Search the Archive

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


  • 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