title: Lua: set every new element in table to a default value
body: <p>I want to get the most frequent k-sized substring in a string. To achieve this, I'm using a table to store the number of occurrences for each substring. Here's the code:</p>
  
  <pre><code>function frequentWords(seq, k)
    local subs = ""
    local counter = {}
    for i = 1,(seq:len()-k+1) do
      subs = seq:sub(i, i+k-1)
      counter[subs] = (counter[subs] and counter[subs] + 1 or 1)
      --print(subs .. ": " .. counter[subs])
    end
  end
  </code></pre>
  
  <p>The line <code>counter[subs] = (counter[subs] and counter[subs] + 1 or 1)</code> has the same mean of  <code>counter[subs] = (counter[subs] ? counter[subs]+1 : 1)</code>. This line would be only <code>counter[subs] = counter[subs] + 1</code> if we could set every new <code>counter</code> element with <code>0</code>. Is this possible in Lua? If not, what's the best way of doing something similar?</p>
  
  <p>For instance, in Ruby, this is done by declaring a Hash like this:</p>
  
  <pre><code>counter = Hash.new(0)
  </code></pre>