next up previous contents
Next: Examing Global Variables from Up: Scoping Rules Previous: Scoping Rules

Independent Scopes

Two variables with the same name but with different scopes are independent of each other. Changing the contents of one variable does not effect the contents of the other. The scope of the local variable u in DummyProcedure_1 below is independent of the scope of variable u in DummyProcedure_2.
> DummyProcedure_1 := proc()
>   lprint('Inside procedure 1');
>   lprint('The value of u before assignment: ', u);
>   u := -8000;
>   lprint('The value of u after assignment: ', u);
> end:

> DummyProcedure_2 := proc()
>   lprint('Inside procedure 2');
>   lprint('The value of u before assignment: ', u);
>   u := 999;
>   lprint('The value of u after assignment: ', u);
> end:
Note that each time we call either of the above procedures, the variable u has no value associated with it initially. Because it does not have a value, Darwin treats u as a name in the lprint command before the assignment of either -8000 or 999 to u. No matter which order or how many times we invoke the dummy_procedures, their local copies of the variable u remain unaffected by the assignments done to the other.
> DummyProcedure_1();
Inside procedure 1
The value of u before assignment:  u
The value of u after assignment:  -8000
> DummyProcedure_2();
Inside procedure 2
The value of u before assignment:  u
The value of u after assignment:  999
> DummyProcedure_1();
Inside procedure 1
The value of u before assignment:  u
The value of u after assignment:  -8000



Gaston Gonnet
1998-09-15