|
[Date Index]
[Thread Index]
[Author Index]
Re: Context
- To: mathgroup at smc.vnet.net
- Subject: [mg70968] Re: [mg70956] Context
- From: Yasvir Tesiram <yat at omrf.ouhsc.edu>
- Date: Fri, 3 Nov 2006 01:39:15 -0500 (EST)
- References: <200611021149.GAA15806@smc.vnet.net>
Hi,
1. You have used SetDelayed.
" lhs := rhs assigns rhs to be the delayed value of lhs. rhs is
maintained in an unevaluated form. When lhs appears, it is replaced
by rhs, evaluated afresh each time. " But this isn't the cause of
your woes.
2. Since fun was never evaluated but only interpreted, you would not
have received the following message:
"Begin::cxt: Invalid context specified at position 1 in Begin[x]. A
context \
must consist of valid symbol names separated by and ending with `."
This isn't the cause of your woes either, but a decent example of how
Mathematica interprets input and is related to 1 above and point 4
below.
3. But here is the most important thing to remember about Mathematica
and variable (name) interpretation. Mathematica interprets names in
an expression by reading the complete expression first. So here, t
has already been interpreted "before" your expression is executed,
and Begin happens to be a part of your expression. In consequence, t
is "globalized" and Begin has no effect.
4. The syntax you have used for Begin is incorrect. It should be
Begin["x`"]
Typically, you would use Begin as the first line and then execute it.
Following this everything belongs in Context "x", until End is
called, wherein the system reverts back to Global context and t
should no longer exist, neither in Context "x", nor Global.
OK, I'm a bit rusty on this myself, but here is a summary and
hopefully it will clear things up for you.
The Context during a fresh start of Mathematica is Global.
When a variable first appears in an expression it is interpreted and
immediately becomes part of the current context.
When Begin is called, it changes the current context. The context is
named (in your case x). There is a special syntax for the argument to
Begin.
When new variables are introduced (actually names), they become part
of the current context.
Related to all of this is $ContextPath, which I won't go into.
Hope this helps alleviate some confusion.
Cheerful regards
Yas
On Nov 2, 2006, at 5:49 AM, dh wrote:
>
> Hello,
>
> consider:
>
> fun[x_]:=( Begin[x];
>
> Print[t];
>
> End[];
>
> );
>
> according to the manual one would think that the variable t in
> context x
>
> is printed. However, this is wrong! What is printed is Global`t.
>
> Therefore, the context to which a symbol belongs is determined during
>
> parsing and NOT execution.
>
> Can anybode give more insight and strict rules for this quirck?
>
> Daniel
>
>
Prev by Date:
Re: RE: Context headache
Next by Date:
Re: Clarification re. Curiosity concerning transformation rules for List
Previous by thread:
Re: Context
Next by thread:
Re: Context
|