I'm getting unexpected behavior when beginning a new context, leaving it, and then re-entering it. Specifically, when re-entering the context, symbols that had been previously defined in that context now seem to have lost their values... but I can recapture them by explicitly supplying the context. Consider this example:
Begin["sandbox`"];
a = 1;
ValueQ[a]
End[];
(* ==> True *)
ValueQ[a]
(* ==> False *)
Begin["sandbox`"];
Names[Evaluate[Context[]] <> "*"]
ValueQ[a]
ValueQ[sandbox`a]
End[];
(* ==> {"sandbox`a"} *)
(* ==> False *)
(* ==> True *)
NB: Quit the Mathematica kernel before evaluating this example, every time. Re-evaluating the whole thing subsequent times changes the results, so that all of the ValueQ tests now return True. (I also have absolutly no idea why that happens.)
My questions are: Why doesn't switching back into the "sandbox`" context give me un-prefixed access to symbols in that context, and is there any way to work around this that doesn't require explicitly providing the context? (In my real application, always specifying the context once it has been left and re-entered isn't practical.)
FYI, the reason I'm investigating this is that I'm trying to set up a kind of clean-ish "sandbox" context where some unknown code can be evaluated, and then test code I've written can inspect the definitions/values/etc. that it leaves behind. Because of the way the application is factored, its hard to avoid leaving and re-entering the sandbox context.