MathGroup Archive 2006

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

Search the Archive

Re: if I open multiple files in Mathematica


As you have discovered, definitions (rules) are associated with a 
Mathematica session and NOT with a Mathematica notebook.

One work-around is to have use a different Mathematica Context for each 
notebook.  A context is essentially a "namespace".  See the Mathematica 
Book's materials for details.

Here's a simple example.  You have two notebooks.  In one you evaluate 
the following input cells:

Begin["This`"]
x=100;
End[]

If you evaluate any cells in that notebook after evaluating the Begin 
cell and the x = 100 cell, but before evaluating the End[] cell, x will 
take the vaule 100 there.

In the other notebook you evaluate input cells:

Begin["Other`"]
x = "hello";
End[]

If you evaluate any cells in that notebook after evaluating the Begin 
cell and the x = "hello" cell, but before evaluating the End[] cell, x 
will take the vaule "hello" there.

But:  After you have evaluated both End[] cells, now no matter in what 
notebook you do further evaluations, if you refer to x you will just get 
the symbol x and neither of those two values.  But if you want to use 
one of the values from within those context, you qualify x with the 
context name:

   This`x
100
   This`x + 23
123

   Other`x
"hello"
   StringJoin[Other`x, ", world!"]
hello, world


Jackie wrote:
> The variables in different files will be cross-referenced. I don't like
>  this feature, What should I do ?
>> thanks.
> 
> 

-- 
Murray Eisenberg                     murray at math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower      phone 413 549-1020 (H)
University of Massachusetts                413 545-2859 (W)
710 North Pleasant Street            fax   413 545-1801
Amherst, MA 01003-9305


  • Prev by Date: Problem to evaluate a function inside a function
  • Next by Date: Re: Matrix decomposition with NullSpace and QRDecomposit
  • Previous by thread: if I open multiple files in Mathematica
  • Next by thread: Re: if I open multiple files in Mathematica