Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2002
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2002

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Re: Work with Contexts

  • To: mathgroup at smc.vnet.net
  • Subject: [mg35790] Re: Re: Work with Contexts
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Wed, 31 Jul 2002 01:33:29 -0400 (EDT)
  • References: <ai06l0$19t$1@smc.vnet.net> <200207290713.DAA05847@smc.vnet.net> <ai5u8n$brs$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Hermann,
> According your theory, I think, "klasse1" should be defined in Global` and
> "klasse" only in Rechteck But this is not the case. Therefore - excuse
me -
> I doubt, that your theory is correct.

I have added some comments to your code about how I think that this happens:


oo`hfield = "klasse1";
oo`newContext[ctxp_] := ($ContextPath = Join[ctxp, $ContextPath];
    BeginPackage[ctxp[[1]]];
    If[Length[ctxp] > 1, $ContextPath = Join[ctxp, Rest[$ContextPath]];])

oo`resumeContext[] := (EndPackage[];
    $ContextPath = Drop[$ContextPath, 1];)

oo`new11[x_] := (Print["Anfang new11"];
    klassnam = x;
    tsx = ToString[klassnam];
    oo`dat = "D:\\Math_OO\\classes\\" <> tsx <> ".cl";
    ctx = klassnam <> "`";
    oo`newContext[{ctx}];)

oo`new12[] := (Print["Name klasse - Anfang"];
      Print["$Context: ", $Context];
      Print["$ContextPath: ", $ContextPath];
      ToExpression[oo`hfield];
      (* the symbol klasse1 is created when oo`new12[] is evaluated*)
      Print["Context von klasse: ", Context[klasse]];
      (*klasse is created as Global`klasse when this rule is read*)
      oo`resumeContext[];
      Print["Name klasse - Ende"];);

Print["Anfang Programm:"];
Print["$Context: ", $Context];
Print["$ContextPath: ", $ContextPath];
oo`new11["Rechteck"];
Print["nach new11:"];
Print["$Context: ", $Context];
Print["$ContextPath: ", $ContextPath];
oo`hfield = "klasse";
oo`new12[];(*klasse and klass1 are created as in context "Rechteck`" when \
this is evaluated, because context,
  contextpath are "Rechteck`", {"Rechteck`", "System`"}*)
Print["nach new12:"];
Print[AH3];
Print["$Context: ", $Context];
Print["$ContextPath: ", $ContextPath];



--
Allan

---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565


"Hermann Schmitt" <schmitther at netcologne.de> wrote in message
news:ai5u8n$brs$1 at smc.vnet.net...
> Hello Allan,
> I have a new program:
>
> oo`hfield = "klasse1";
> oo`newContext[ctxp_] := (
>
>   $ContextPath = Join[ctxp, $ContextPath];
>       BeginPackage[ctxp[[1]]];
>    If[Length[ctxp]>1,
>        $ContextPath = Join[ctxp, Rest[$ContextPath]];
>     ]
>     )
> oo`resumeContext[] := (
>         EndPackage[];
>        $ContextPath = Drop[$ContextPath, 1];
> )
> oo`new11[x_] := (
> Print["Anfang new11"];
> klassnam = x;
> tsx = ToString[klassnam];
> oo`dat = "D:\\Math_OO\\classes\\" <> tsx <> ".cl";
> ctx = klassnam <> "`";
> oo`newContext[{ctx}];
> )
> oo`new12[] := (
> Print["Name klasse - Anfang"];
>  Print["$Context: ", $Context];
>  Print["$ContextPath: ", $ContextPath];
>  ToExpression[oo`hfield];
>  Print["Context von klasse: ", Context[klasse]];
>  oo`resumeContext[];
>  Print["Name klasse - Ende"];
>  );
>   Print["Anfang Programm:"];
>   Print["$Context: ", $Context];
>  Print["$ContextPath: ", $ContextPath];
>  oo`new11["Rechteck"];
>   Print["nach new11:"];
>   Print["$Context: ", $Context];
>  Print["$ContextPath: ", $ContextPath];
>  oo`hfield = "klasse";
>  oo`new12[];
>    Print["nach new12:"];
>    Print["$Context: ", $Context];
>  Print["$ContextPath: ", $ContextPath];
>
> and the results:
>
> Anfang Programm:
> $Context: Global`
> $ContextPath: {Global`, System`}
> Anfang new11
> nach new11:
> $Context: Rechteck`
> $ContextPath: {Rechteck`, System`}
> Name klasse - Anfang
> $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 von klasse:
> Global`
> Name klasse - Ende
> nach new12:
> $Context: Global`
> $ContextPath: {Global`, System`}
> In[19]:=
>
> According your theory, I think, "klasse1" should be defined in Global` and
> "klasse" only in Rechteck But this is not the case. Therefore - excuse
me -
> I doubt, that your theory is correct.
>
> Hermann Schmitt
>
> ----- Original Message -----
> From: "Allan Hayes" <hay at haystack.demon.co.uk>
To: mathgroup at smc.vnet.net
> Subject: [mg35790]  Re: Work with Contexts
>
>
> > Hermann,
> >
> > > My question is:
> > > Why is the variable "klasse" also defined in the context Global?
> >
> > klasse is created in the context "Global`" when the assignment
> >
> > 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"];)
> >
> > is converted into internal form (with contexted symbols) prior to
> > evaluation.
> >
> > This is before
> >     oo`new11["Rechteck"];
> > is evaluated
> >
> > --
> > Allan
> >
> > ---------------------
> > Allan Hayes
> > Mathematica Training and Consulting
> > Leicester UK
> > www.haystack.demon.co.uk
> > hay at haystack.demon.co.uk
> > Voice: +44 (0)116 271 4198
> > Fax: +44 (0)870 164 0565
> >
> >
> > "Hermann Schmitt" <schmitther at netcologne.de> wrote in message
> > news:ai06l0$19t$1 at smc.vnet.net...
> > > 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
> > >
> > >
> > >
> >
> >
> >
>
>




  • Prev by Date: Re: Work with Contexts
  • Previous by thread: Re: Work with Contexts
  • Next by thread: Re: Work with Contexts