Re: Context headache

*To*: mathgroup at smc.vnet.net*Subject*: [mg70929] Re: [mg70907] Context headache*From*: "Chris Chiasson" <chris at chiasson.name>*Date*: Thu, 2 Nov 2006 06:46:58 -0500 (EST)*References*: <200611010855.DAA01540@smc.vnet.net>

I would guess the problem is that your analysis functions are generating the names of these data variables instead of receiving them. You could change it so that the analysis functions accept another argument to which the analysis functions assign values. for example: myanalysis[symb_Symbol,dat:{__?NumberQ}]:=symb=Plus@@dat; then you could feed the function as follows: myanalysis[cont1`data,{1,2,3}] myanalysis[cont2`data,{1,a,0,p}] P.S. I didn't read that other thread, so I don't know if this was already said. On 11/1/06, Xerxes <Xerxes314 at gmail.com> 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 > http://groups.google.com/group/comp.soft-sys.math.mathematica/msg/7368d0cd14aa8960 > (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 > > -- http://chris.chiasson.name/

**References**:**Context headache***From:*"Xerxes" <Xerxes314@gmail.com>