global variable problem - still local 
Author Message
 global variable problem - still local

Hello,
I noticed this problem in one of my procs. I wrote such a code:

proc WFAddElement { w x y } {

  global DEBUG WFDescr WFRepository
  puts stdout "locals = [info locals]
  ...
  }

and e.g. the WFDescr was reported as local variable and it really was
treated such way. When I assigned something to it, the change was
visible in the proc, but not outside.

In my program there are tens of such procs with the same code, which
work OK. Just this one does not. I checked mistypings (OK), syntax,
braces (OK), used the Procheck and did not get any error or warning
message.

Did somebody have similar problem already? I used any mans I have
found on Inet, but did not found solution.

Thanks,
Pavel Hampl



Sat, 24 Jul 2004 17:33:02 GMT  
 global variable problem - still local
Quote:

> Hello,
> I noticed this problem in one of my procs. I wrote such a code:

> proc WFAddElement { w x y } {

>   global DEBUG WFDescr WFRepository
>   puts stdout "locals = [info locals]
>   ...
>   }

> and e.g. the WFDescr was reported as local variable and it really was
> treated such way. When I assigned something to it, the change was
> visible in the proc, but not outside.

> In my program there are tens of such procs with the same code, which
> work OK. Just this one does not. I checked mistypings (OK), syntax,
> braces (OK), used the Procheck and did not get any error or warning
> message.

> Did somebody have similar problem already? I used any mans I have
> found on Inet, but did not found solution.

Just tried your example (fixing the missing " after puts stdout ...)
(Tcl 8.3.4)

% proc WFAddElement {w x y} {

global DEBUG WFDescr WFRepository
puts stdout "locals = [info locals]"

Quote:
}

% WFAddElement 1 2 3
locals = w x y
%

Works ok for me.

Michael Schlenker



Sat, 24 Jul 2004 17:55:12 GMT  
 global variable problem - still local

Quote:

> Just tried your example (fixing the missing " after puts stdout ...)
> (Tcl 8.3.4)

> % proc WFAddElement {w x y} {

> global DEBUG WFDescr WFRepository
> puts stdout "locals = [info locals]"
> }
> % WFAddElement 1 2 3
> locals = w x y
> %

> Works ok for me.

> Michael Schlenker

Sorry for troubling you, the problem was elsewhere and only looked
like "global variable" problem. I have found it and repaired now. The
main source was between the keyboard and the chair.

I have noticed some thread before which was discussing the improper
behavior of "info locals".



Sat, 24 Jul 2004 21:08:56 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. promoting variables from local to global problem

2. Printing Local And Global Variables

3. Faster: Sequence Local or Global Variable?

4. LOGO-L> local and global variables

5. Local and Global variables

6. Global, local variables in SubVI's

7. local variable and local variable in block behave differently

8. Local/global variable dilemma

9. top-level (global) vs internal (local) variables/definitions

10. Local vs global variables in ADA

11. Global vs Local variable

12. global variables and local functions.

 

 
Powered by phpBB® Forum Software