May be someone can explain why I can't use Begin["context`"]
and End[]
inside a Manipulate
expression, or inside the initialization section?
When I use it in the Manipulate
expression, and close the notebook and restart, I get the error:
Here is the code, please feel free to modify as needed. I am just trying to see if the idea of different contexts can be used inside Manipulate. It is just not seeing obj`f[]
at all.
Manipulate[
Begin["obj`"];
f[y_] := y^2 + 1;
End[];
{x, Date[], obj`f[1]},
{{x, 0, "x"}, 0, 10, 1, Appearance -> "Labeled"},
TrackedSymbols :> {x}
]
I also tried in the initialization section, same problem. I think this is because Manipulate
itself is a Dynamic
module, it does not like new context created inside it?
This is a snapshot of the above:
DynamicModule[{x = 5},
Begin["obj`"];
f[y_] := y^2 + 1;
End[];
{x, Date[], obj`f[1]}
]
Outside Manipulate
, it works fine of course: (restating kernel helps before running this below again after the above just in case)
Begin["obj`"];
f[y_] := y^2 + 1;
End[];
obj`f[2]
gives 5