# Why must I specify the Global context for a symbol in a private package?

I have written two versions of the function below in a package. When I load the package and call the function, Why does the first version where the variable s has no explicit Context return the long variable name? Or why do I have to put the variable in the Global context to return the short name? While every other function component is automatically assigned to the package context. Is there something weird happening with the Block function?

x={{k1p -> 6.680629079305845, k1m -> 9.100970498785017,
k2p -> 5.9669213788246225, state -> 1.}, {k1p -> 6.680629079305845,
k1m -> 9.100970498785017, k2p -> 5.9669213788246225, state -> 0.}}
signal_:signal,numberOfStrains_:numberOfStrains]:=
Block[{variateList,s,i,j},
variateList = params;
(*Prepare each jth simulation parameter list by
mutantParameters =
Table[
Join[{s->j},variateList[[i]]],
{j,signal},
{i,1,numberOfStrains}
]
];
({SimulatorV2DebugPrivates->1,k1p->6.68063,k1m->9.10097,k2p>5.96692,state->1.}
{SimulatorV2DebugPrivates->1,k1p->6.68063,k1m->9.10097,k2p->5.96692,state->0.}
{SimulatorV2DebugPrivates->3,k1p->6.68063,k1m->9.10097,k2p->5.96692,state->1.}
{SimulatorV2DebugPrivates->3,k1p->6.68063,k1m->9.10097,k2p->5.96692,state->0.}
{SimulatorV2DebugPrivates->5,k1p->6.68063,k1m->9.10097,k2p->5.96692,state->1.}
{s->5,k1p->6.68063,k1m->9.10097,k2p->5.96692,state->0.})

signal_:signal,numberOfStrains_:numberOfStrains]:=
Block[{variateList,s,i,j},
variateList = params;
(*Prepare each jth simulation parameter list by
mutantParameters =
Table[
Join[{Globals->j},variateList[[i]]],
{j,signal},
{i,1,numberOfStrains}
]
];
({s->1,k1p->6.68063,k1m->9.10097,k2p>5.96692,state->1.}
{s->1,k1p->6.68063,k1m->9.10097,k2p->5.96692,state->0.}
{s->3,k1p->6.68063,k1m->9.10097,k2p->5.96692,state->1.}
{s->3,k1p->6.68063,k1m->9.10097,k2p->5.96692,state->0.}
{s->5,k1p->6.68063,k1m->9.10097,k2p->5.96692,state->1.}
{s->5,k1p->6.68063,k1m->9.10097,k2p->5.96692,state->0.})


Every symbol always has a context. Most of the time we are in the Global context.

$Context (* "Global" *)  Normally we don't have to specify a variable as Globals  Simply writing s is sufficient provided we are in the Global context. Inside your package the symbols and functions are defined in the SimulatorV2DebugPrivate  context. In the function threadParameters inside the Block the variable s is from that context. That is why you get the two different results. One s is in the SimulatorV2DebugPrivate  context and you get for example: {SimulatorV2DebugPrivates->1,k1p->6.68063,k1m->9.10097,k2p>5.96692,state->1.}  Two In your function you explcity use: Join[{Globals->j},variateList[[i]]],  so s is in the Global context and you get: {s->1,k1p->6.68063,k1m->9.10097,k2p>5.96692,state->1.}  Note that this is the same as: {Globals->1,k1p->6.68063,k1m->9.10097,k2p>5.96692,state->1.}  Simply because $Context is Global, the long name is not written.

PS

I didn't want to introduce a diversion but in your second definition you are missing a comma here:

threadParameters[epsilon_/;epsilon==1,k_,params_
`

I suspect that is simply a copy and paste error.

• Ah yes, that is a typo. Now fixed. – tarhawk Nov 7 '15 at 18:28