MathGroup Archive 2006

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

Search the Archive

Re: Context headache

  • To: mathgroup at
  • Subject: [mg70932] Re: Context headache
  • From: dh <dh at>
  • Date: Thu, 2 Nov 2006 06:47:07 -0500 (EST)
  • References: <ei9p0d$22s$>

Hi Xerxes,

a function that iterates over contexts can be made by specifying the 

fully qualified symbol names. Here is an example. First we set up 2 

symbols in 2 different contexts:







now we use a function that prints variables in these contexts:

(   Print[Symbol[#<>"t1"]];

  )& /@{"test1`","test2`"}


Xerxes wrote:

> Hi all,


> I'm trying to write a Mathematica analysis package in which

> various data sets are distinguished by being placed in their

> own contexts, say data1`data, data2`data, etc. This is helpful

> in that you can always hop into a context to work with each

> data set individually. Of course, at some point, that method

> becomes too much of a chore and you want to automate things.

> I'm trying to make a function that iterates over several contexts;

> it will hop into the context, execute a function on the data in

> that context, save the result as another variable in that context

> and then hop back out.


> But as described in


> (thread aptly named "Nailing jelly to a tree"), you can't do this.

> As soon as you try evaluating the iterating function, all the

> variables inside it get poisoned with the Global` context. You

> might try fixing this by using more nails on the jelly, say

> a hideous construct like


> Evaluate[Symbol[$Context<>"result"]] =

>   analyze[Evaluate[Symbol[$Context<>"data"]]];


> but since my actual functions are much more complicated than

> this simple example, any readability of the code goes right away.


> Is there any better workaround known that would allow

> iteration over multiple contexts?


> Or alternatively, since it seems like I'm trying to force contexts

> to do something they don't want to do, is there some better

> data encapsulation technique I haven't thought of yet?


> Thanks,

> Xerxes


  • Prev by Date: Re: Two small problems compute OK, but not their sum.
  • Next by Date: RE: Adding a key binding for a Style
  • Previous by thread: Re: RE: Context headache
  • Next by thread: Re: Matching with a "Flat" function