Posted to tcl by aspect at Wed Nov 30 03:33:40 GMT 2011view raw

  1. Variable resolution
  2. -------------------
  3. Unlike the variable command in Tcl, the variable command in Jim Tcl
  4. is an identical analog to the global command. The variable command
  5. creates a link from a local variable to a namespace variable.
  6.  
  7. **
  8. Invoked with two arguments, it also sets the value of the linked variable.
  9.  
  10. namespace eval ::test {
  11. variable myvar 4
  12. }
  13. **
  14.  
  15.  
  16. For example, the following procedure uses 'variable' to access myvar.
  17.  
  18. proc ::test::myproc {} {
  19. variable myvar
  20. incr myvar
  21. }
  22.  
  23. Note that there is no automatic resolution of namespace variables.
  24. For example, the following will *not* work.
  25.  
  26. namespace eval ::test {
  27. variable myvar 4
  28. }
  29. namespace eval ::test {
  30. # This will increment a local variable, not ::test::myvar
  31. incr myvar
  32. }
  33.  
  34. In the same way that variable resolution does not "fall back" to
  35. global variables, it also does not "fall back" to namespace variables.
  36.  
  37.