Re: Work with Contexts
- To: mathgroup at smc.vnet.net
- Subject: [mg35758] Re: Work with Contexts
- From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
- Date: Tue, 30 Jul 2002 07:22:04 -0400 (EDT)
- Organization: Universitaet Leipzig
- References: <ai06l0$19t$1@smc.vnet.net>
- Reply-to: kuska at informatik.uni-leipzig.de
- Sender: owner-wri-mathgroup at wolfram.com
Hi, the variable klasse becomes defined when you give the definition for oo`new21[] Just try it out and evaluate only the oo`* defintions and Names["Global`*"] will list {"ctx", "ctxp", "klasse", "klassnam"} The problem is, that you use Print["Context of klasse: ", Context[klasse]]; in your definition and this will create the klasse symbol when oo`new21[] is defined. Regards Jens Hermann Schmitt wrote: > > Hello, > I have the following program: > > oo`newContext[ctxp_] := ( > BeginPackage[ctxp[[1]]]; > ) > oo`resumeContext[] := ( > EndPackage[]; > $ContextPath = Drop[$ContextPath, 1]; > ) > oo`new11[x_] := ( > Print["Begin new11"]; > klassnam = x; > ctx = klassnam <> "`"; > oo`newContext[{ctx}]; > ); > oo`new12[] := ( > Print["Name klasse - Begin"]; > Print["$Context: ", $Context]; > Print["$ContextPath: ", $ContextPath]; > ToExpression["klasse"]; > Print["Context of klasse: ", Context[klasse]]; > oo`resumeContext[]; > Print["Name klasse - End"]; > ); > Print["Begin Programm:"]; > Print["$Context: ", $Context]; > Print["$ContextPath: ", $ContextPath]; > oo`new11["Rechteck"]; > oo`new12[]; > Print["after new12:"]; > Print["$Context: ", $Context]; > Print["$ContextPath: ", $ContextPath]; > > I get the following results: > > Begin Programm: > $Context: Global` > $ContextPath: {Global`, System`} > Begin new11 > Name klasse - Begin > $Context: Rechteck` > $ContextPath: {Rechteck`, System`} > klasse > klasse::shdw: Symbol klasse appears in multiple contexts {Rechteck`, > Global`} > ; definitions in context Rechteck` > may shadow or be shadowed by other definitions.Context of klasse: > Global` > Name klasse - End > after new12: > $Context: Global` > $ContextPath: {Global`, System`} > In[14]:= > > My question is: > Why is the variable "klasse" also defined in the context Global? > > Hermann Schmitt