Posted to tcl by aspect at Mon Sep 30 11:02:02 GMT 2019view raw

  1. namespace eval myNum {
  2. set num "0"
  3.  
  4. proc myNum {} {
  5. variable num
  6.  
  7. for {set i 0} {$i < 10} {incr i} {
  8. if {[info exists num]} {
  9. set num [expr 1 + $num]
  10. } else {
  11. set num 1
  12. }
  13. }
  14.  
  15. puts $num
  16. }
  17.  
  18. namespace export myNum
  19. }
  20.  
  21. namespace import myNum::*
  22.  
  23. myNum
  24. puts "num exists? [info exists num]"
  25. puts "But it does exist as $myNum::num"
  26.  
  27.