Re: Problem with Contexts
- To: mathgroup at christensen.Cybernetics.NET
- Subject: [mg400] Re: [mg393] Problem with Contexts
- From: Leendert van Gastel <gastel at can.nl>
- Date: Thu, 12 Jan 1995 13:20:42 +0100
> I experienced the following problem when defining Contexts:
>
> Mathematica 2.2 for NeXT
> Copyright 1988-93 Wolfram Research, Inc.
> -- NeXT graphics initialized --
> In[1]:= Begin["Alice`"]
> Out[1]= Alice`
> In[2]:= x=1;y=2;x+y
> Out[2]= 3
> In[3]:= Begin["Bob`"]
> Out[3]= Bob`
> In[4]:= x=11;y=22;x+y
> Out[4]= 33
> In[5]:= Begin["Alice`"];y-x
> Out[5]= 11
> In[6]:= y-x
> Out[6]= 1
> In[7]:= Exit
Dear Charlie,
The change in the context is only effectuated when the command
it is part of, is processed completely.
This happens to be the way that it works, I noticed it once myself.
The full form of a;b is CompoundExpression[a, b], so when
a=Begin["Alice`"], this change is performed after the complete
CompoundExpression is evaluated.
In your example below, the lines read actually
first line:
Begin["Alice`"]; Null
second line:
y-x
The lines that form complete expressions in one cell are processed one by one
and so the change in context is performed after executing the first line.
>
> For the In[5] I try to change the Context and do a calculation in
> the same command, but the calculation is done using the previous
> Context ("Bob"). However, the Context was changed as noted when
> the calculation is repeated (In[6]). Is this a bug or am I missing
> something about how Contexts are used and defined.
>
> BTW--I found the same problem when using the Notebook interface BUT
> when I concatenate the commands on separate lines it works okay--
>
> Begin["Alice"];y-x
>
> doesn't work, but
>
> Begin["Alice"];
> y-x
> (the Shift-Return)
>
> does work.
>
> Thanks for the help,
> Charlie
>
> --
> NeXTMail to: | ...to confer, converse, and
> charlie at technosci.com | otherwise hobnob with my
> | brother wizards.
>
>