title: function to calculate the sum of a given array
body: <p>I am new to Tcl so i am learning the basics. I wrote a function to calculate the sum of an array and print its elements. Here is the code</p>
  
  <pre><code>proc print_sum { tab } {
      set s 0
      foreach key [array names tab] {
          puts "${key}=$tab($key)"
          incr $s $tab($key)  
      }
      puts "the sum = $s"
  }
  </code></pre>
  
  <p>Here is how I called it:</p>
  
  <pre><code>print_sum tab
  </code></pre>
  
  <p>and I created the tab like this:</p>
  
  <pre><code>set tab("1") 41
  set tab("m2") 5
  set tab("3") 3
  set tab("tp") 9
  set tab("2") 7
  set tab("100") 16
  </code></pre>
  
  <p>But the output is wrong! It outputs 0 instead of the actual sum and it does not output any element. But when I used the code directly without writing it in a function, it works.</p>