leafo/moonscript — Issue #30: Scope blocks
Author: ckknight
Created: 2012-02-19 07:58:13+00:00
State: open

In lua, you can introduce new scope easily with `do ... end`, it would be nice to do the same in MoonScript.

Ideally, I want something like this to work:

myFunction = do
hidden = { a: 1, b: 2, c: 3 }
(key) -> hidden[key]

Which would compile into something along the lines of this:

local myFunction
do
local hidden = { a = 1, b = 2, c = 3 }
myFunction = function (key)
return hidden[key]
end
end

Or

local myFunction = (function ()
local hidden = { a = 1, b = 2, c = 3 }
return function (key)
return hidden[key]
end
end)()