Hacker News new | ask | show | jobs
by jacktoole1 4967 days ago
It's great to see more development of the language! MoonScript is great if you're looking for the niceness of CoffeeScript in an embedded environment (Lua's semantics also behave more sanely than Javascript's). I have roughly 5000 lines of MoonScript powering my side project [1], and it's been a pleasure to write.

Any thoughts of letting the 'do' keyword support coffeescript-style 'do' semantics as well? Invoking a multi-line anonymous function is currently a bit impractical, and allowing do to invoke a single function parameter would make that a lot nicer, and allow for capturing variable's in a closure more easily. Example from the coffeescript docs:

  for filename in list
    do (filename) ->
      fs.readFile filename, (err, contents) ->
        compile filename, contents.toString()
[1] http://www.codingspellbook.com/
1 comments

I've thought about this. It doesn't make as much sense in Lua. An iterated variable it gets it's own local assignment for each iteration. The variable isn't shared like JavaScript:

http://moonscript.org/compiler/#14

Here I create 10 functions closed on the loop value. Then I loop over them and call them all. In JavaScript this would print 10 10 times, but in Lua we get the 1 through 10.

Cool! I was aware that variable reassignment didn't carry over in for loops, but I didn't know that the variables in each iteration were independent.

Keep up the good work!