title: default values and variable scope
body: <p>I think I am missing something about how variable scopes and or default value work lua. Consider the following function:</p>
  
  <pre><code>function printtable(x, indentation_level)
  
     indentation_level = indentation_level or 0
  
     function indent()
        dent = ''
        for i=1,indentation_level do
           dent = dent..'__'
        end
        return dent
     end
  
     if type(x) ~= 'table' then
        return tostring(x)
     end
  
     rpr = ''
     for k, v in pairs(x) do
        rpr = rpr..indent()..'['..printtable(k)..']'..' = '..printtable(v, indentation_level+1)
     end
     return rpr
  end
  </code></pre>
  
  <p>when I invoke it with </p>
  
  <pre><code>t = {1,2,3}
  
  print(printtable(t))
  </code></pre>
  
  <p>I will get <code>[1] = 1__[2] = 2__[3] = 3</code></p>
  
  <p>What I expected is <code>[1] = 1[2] = 2[3] = 3</code></p>
  
  <p>I rewrote the function in python to see where my logic error is:</p>
  
  <pre><code>def printdict(x, indentation_level=0):
  
      def indent():
  
          dent = ''
          for i in range(indentation_level):
              dent += '__'
          return dent
  
      if type(x) != dict:
          return str(x)
  
      rpr = ''
      for k, v in x.items():
          rpr = rpr+indent()+'['+printdict(k)+'] = '+printdict(v, indentation_level+1)
  
      return rpr
  </code></pre>
  
  <p>And when I invoke it with:</p>
  
  <pre><code>t = {1:1,2:2,3:3}
  
  print(printdict(t))
  </code></pre>
  
  <p>I get what I would expect: <code>[1] = 1[2] = 2[3] = 3</code></p>
  
  <p>So, what is going on with the lua version? What am I missing about variable scope or some other mechanic that causes the difference?</p>