Hacker News new | ask | show | jobs
by eatnumber1 4342 days ago
Great! Can you submit a pull request?
2 comments

Straightforward solution:

    function g(o)
      if o then return "gal" end
      o = "o"
      local function go(al)
        if al then
          return "g"..o..al
        else
          o = o .. "o"
          return go
        end
      end
      return go
    end
    print(g()('al'))
More amusing and hackish solution:

    setmetatable(_G, -- or _ENV, but maintain 5.1 compatibility
      { __index = function(_, g)
        local o = ""
        local function go(al)
          if al then
            return g..o..al
          end
          o = o.."o"
          return go
        end
        return go
      end})
    print(g()('al'))
    print(G()'al')
    print(Wh()()'pdedo')
a straightfoward translation of the Javascript version w/ closures should work

    function goal(n)
       return function(al)
           if al then
               return "G" .. string.rep("o", n) .. al
           else
               return goal(n+1)
           end
       end
    end

    G = goal(0)

    print( G()()('al') )
Also note that G()'al' is just syntactic sugar for G()('al') in Lua