

MoonScript v0.2.2 is released - leafo
http://leafo.net/posts/moonscript_v022.html

======
jacktoole1
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/>

~~~
leafo
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.

~~~
jacktoole1
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!

------
lukegru
Cool project! Just wondering why you decided to roll your own parser. Is there
a lua parser generator library?

I've been working on a source translator, sort of like coffeescript for VimL
[1], and I can't imagine writing the parser myself instead a BNF grammar (but
please correct me if I'm wrong, I only took a cursory look at the src)

[1] <https://github.com/luke-gru/riml>

~~~
leafo
I didn't roll my own parser generator, I used LPeg: <http://www.inf.puc-
rio.br/~roberto/lpeg/>

It's a great library, I highly recommend it.

I've assembled a few parsers using various tools, and I must say PEGs are my
favorite. They are very flexible and performance is comparable. (even
CoffeeScript 2.0 is being written with a PEG.)

You can check out the guts of the parser here:
[https://github.com/leafo/moonscript/blob/master/moonscript/p...](https://github.com/leafo/moonscript/blob/master/moonscript/parse.lua#L377)

~~~
lukegru
Ah, ok cool. I haven't tried using PEGs and I don't even know the theory
behind it, so I'm watching a video [1] by the author of LPEG now, which is
quite good. Cheers!

[1] <http://vimeo.com/1485123>

------
thirdreplicator
What's so great about compiling to Lua?

~~~
fab13n
CoffeeScript hides the most hideous warts of JavaScript. It's worth it because
although messy as Hell, JS has an amazing ecosystem, most
importantly/obvioulsy the ability to run in a client's browser.

If I get it right, MoonScript aims at doing the same for Lua. The difference
is that (1) Lua ecosystem isn't nearly as unavoidable as JS' and (2) Although
some design decisions in Lua aren't consensual, the one thing you cannot call
the language is "messy". IMO, Lua's main drawback is that by being so flexible
and lacking an interventionist benevolent dictator, it doesn't grow standard
coding practices, as Python does. Of course, creating alternative syntaxes
isn't likely to improve the matter.

But in the end, it's fun to write compilers, and this is a perfectly
legitimate reason to write one.

~~~
jacktoole1
The lua ecosystem is extremely simple to embed in a native application, which,
as someone who has had to do it, is something that feels underappreciated.
Python and javascript were harder to set up for embedding on the same
computer, and all but impossible to cross-compile for iOS. The simplicity of
using lua as a scripting language in larger applications makes it a great
target for compilation.

MoonScript also gets rid of a lot of the more verbose parts of lua, and
replaces them with CoffeeScript-like versions. For example: shorter anonymous
function syntax, syntactically significant whitespace, default local
variables.

------
malkia
Is there an emacs-mode for it?

~~~
leafo
Nope. I know nothing about emacs so I haven't even attempted it. I'm sure the
CoffeeScript one could be slightly modified to fit MoonScript.

