MathGroup Archive 2008

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

Search the Archive

Re: How to make variable have package scope but not global scope.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg90416] Re: How to make variable have package scope but not global scope.
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Tue, 8 Jul 2008 07:49:44 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, UK
  • References: <g4v33p$ih2$1@smc.vnet.net>

jeremito wrote:

> I am a beginner in package development in Mathematica.  I need a
> package because I have several functions that call each other that
> depend on the same data.  Instead copying and passing the data around,
> I want to have the functions all access the data directly.
> 
> My package currently looks like:
> 
> f[A_, x_] := Module[{},
> b = A.x;
> Return[{b,A}];
> ]


It would be much better to write it as follows (local variables and no 
Return statement):

   f[A_, x_] := Module[{b},
     (* b is now a local variable to the function f *)
     b = A.x;
     {b,A}
     (* Last expression is returned if it does not end by a semicolon *)
   ]
   (* b is not visible outside the scope of Module *)


> g[A_, l_] := Module[{},
> ....
> (*You get the picture*)
> ]
> 
> 
> So my question is, how can my variables have package scope, but not
> global scope?  What is the best way to implement this?

Not sure what you mean by that. Are you talking about contexts? In this 
case, the following might help:

http://reference.wolfram.com/mathematica/tutorial/Contexts.html

http://reference.wolfram.com/mathematica/tutorial/ManipulatingSymbolsAndContextsByName.html

Regards,
-- Jean-Marc


  • Prev by Date: PlotRange Trouble
  • Next by Date: Re: Extracting points from a contour plot
  • Previous by thread: How to make variable have package scope but not global scope.
  • Next by thread: Trouble related to "CSV"