MathGroup Archive 2008

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

Search the Archive

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


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"