25 ms·
Great! Can you submit a pull request?
by eatnumber1 12y ago
Great! Can you submit a pull request?
- ufo 12y agoa 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
- whoopdedo 12y agoStraightforward 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')