moonscript icon indicating copy to clipboard operation
moonscript copied to clipboard

return and assignment on same line?

Open aleclarson opened this issue 7 years ago • 0 comments

return foo = -> foo!

..would compile to:

local foo
foo = function()
  return foo()
end
return foo

Apart from returning a function that calls itself, another use case is expecting the last assignment in a function to implicitly return:

i = 0
incr = -> i += 1

..would compile to:

local i = 0
local incr
incr = function()
  i = i + 1
  return i
end

aleclarson avatar Feb 22 '18 18:02 aleclarson