
MoonScript - A programmer friendly language that compiles to Lua. - newtonapple
http://moonscript.org/
======
jacques_chester
I quite like the lua syntax as-is.

It's simple, predictable and easy to read.

This obsession with boiling everything down to strings of symbols is how folk
wind up making fun of Perl and OCaml.

What's this do?

    
    
        $$&[%]
    

Or this?

    
    
        ?:>
    

Buggered if I know. _Only a professional Perl or OCaml programmer could tell
you_ \-- and indeed I made those up. Only a professional Perl or OCaml
programmer could tell if they do anything at all.

But pretty much anyone from any language background can eyeball an Algol-
family syntax and tell you what's going down.

~~~
chc
I think you must be confused. OCaml is not all that punctuation heavy and
doesn't have overloaded operators to make it punctuation heavy.

~~~
jacques_chester
I must be, but here's how I remember it (bearing in mind that memory is
faulty).

A few years ago I took a unit in my comp sci degree, "Programming Paradigms".
The language used for teaching was F#, which is heavily inspired by OCaml. At
one point we were given readings on OCaml programs and a particular operator
popped up -- something like "is subtype of", I fail to recall exactly -- and
it looked like :>? or :?> or similar.

I bitched loudly in the unit forum about this operator, whereupon the
professor politely informed me that he, in fact, had invented that little bit
of syntax when he was a PhD student at INRIA.

He didn't flunk me! Dr Rowan Davies, still the most scary-smart computer
scientist I've met.

~~~
silentbicycle
I haven't ever seen that in OCaml. Probably an F# extension.

If you're going to complain about OCaml's syntax, I would start with having to
use different arithmetic ops for int vs. floating point (+ vs. +.) and
different indexing operators for strings and arrays ( s.(0) vs. s.[0] ).

You get used to it pretty quickly, and OCaml more than makes up for it in
other ways, but it is a bit annoying.

~~~
jacques_chester
He mentioned that he did a bunch of work object-system work on Caml that was
published, but the INRIA guys didn't put it into the main version when they
developed OCaml. It's possible it got transmitted into F# that way. Next time
I see him I'll ask about it.

------
gmac
Almost all the examples look like pure CoffeeScript (so I find it strange that
this isn't mentioned/namechecked anywhere on the site).

Edit: happily, an attribution has now been added at the bottom, as noted in
child comments.

~~~
clyfe
Indeed. It also saddens me that it does not stick to CS conventions - lots of
extra cruft ( the ! for zero-arity method invocation -- instead # for comments
etc )

~~~
ColinWright
Are you actually claiming that "#" is a computer science convention for
comments? It's not used in C, C++, Fortran, Lua, or many other languages. For
example, comments in OCaml are ( * ... * ) (I've put extra spaces to thwart
HN's formatting.

Language using "--" for comments include Lua and Haskell.

You've made me curious - what languages to you use/know that make you think
"#" is a "CS convention" for comments?

EDIT: Found a reference:

[http://en.wikipedia.org/wiki/Comparison_of_programming_langu...](http://en.wikipedia.org/wiki/Comparison_of_programming_languages_%28syntax%29#Comments)

Further edit: In response to the clarification that CS meant CoffeeScript and
not Computer Science (nor the riot control gas), the point, I guess, then
follows other commentators, who observe that Lua, to which this compiles, uses
"--".

~~~
Cushman
But you're after the right point— the languages are bash, Perl, Python, Ruby.
It's a scripting language convention, hence why CoffeeScript adopted it over
JavaScript's `//`, hence the confusion as to why MoonScript didn't.

------
skrebbel
In all honesty, what's the point of this? I understand the point of compiling
to JavaScript simply because that's the only language that runs on the most
ubiquitous platform in the world. Why compile to any other high-level
language?

Are there so many similar places where users are forced to use Lua, to warrant
an extra layer? (with all the complexities such as debugging, a compile step,
tracing errors back to MoonScript code, etc)

Note, I'm not commenting about the language's choices. Maybe coding in
MoonScript rocks big time. I just don't get why it compiles to Lua.

~~~
silentbicycle
It'd make more sense to me if it were compiling a very different _kind_ of
language, such as a Constraint/Logic programming language. I really like Lua
for scripting, as-is.

Lua's portability & smooth C integration make it an interesting code
generation target (not to mention LuaJIT's performance). And however you feel
about working in Lua, its code is straightforward to generate - the syntax is
refreshingly free of odd corner cases.

~~~
jethroalias97
It is odd the designer decided to compile to lua. It's probably because it's
easier to knock out the language fast that way. Although usually when someone
wants to do this they compile to C and use gcc from there (this is what go did
in the beginning), but they also usually admit this is a hack, not a feature
and that they will later compile directly to assembly.

------
wildmXranat
If this compiles into Lua/JIT bytecode then there might be a use for it, if
this transforms into Lua code then what is the point? Lua is a great and
simple language, so this would seem useless

~~~
wisty
Not everyone thinks that Lua is great. It's certainly a nice language, and
it's popular in some niches, but some people like implicit variable
declarations, classes (at times), and comprehensions.

Also, I can see it compiling into JavaScript as well. I'm not sure if that
would be a good idea, or a really horrible one, though.

~~~
jacques_chester
It's not an acronym, it's an ordinary noun: Lua.

My main grudge against Lua purely as a language is that it has implicit global
variables. I can live with the rest of the idiosyncracies.

My main grudge in day-to-day programming is the ecosystem, it's very small.
It's a chicken-and-egg thing.

------
neworbit
Very cool. I confess I'm not likely to use it anytime soon, since I am
conversant with how Lua works today and not so much with Coffeescript, but I'm
glad for the aid to adoption!

------
rbxbx
The killer feature of MoonScript would be 0 based indexes. See no mention of
it though...

------
aashay
Anybody try writing an iPhone app with MoonScript -> Lua -> Wax -> Objective
C?

~~~
chriseidhof
Exactly! I think they only need some kind of way to add syntax for obj-c style
messages.

If only objc would remove the square brackets (and stay true to smalltalk),
the syntax would be so much nicer:

NSArray* array = NSArray alloc init autorelease NSDictionary* dict =
NSDictionary dictionaryWithObjectsAndKeys:obj,key,nil

...

~~~
jacques_chester
> Exactly! I think they only need some kind of way to add syntax for obj-c
> style messages.

<http://olua.sourceforge.net/> ?

> If only objc would remove the square brackets (and stay true to smalltalk),
> the syntax would be so much nicer:

Objective C is (or at least it used to be, not sure ATM) a strict superset of
C. One of the ways this is achieved is through having orthogonal syntax for
the smalltalk-ish bits compared to classic C.

------
stephth
This looks very promising. Congrats on the launch.

I am enjoying this wave of new programming languages that compile down to
existing ones in a human readable way. They are pleasant to write and read and
yet performant and don't require a special runtime, making them easy to
integrate anywhere in their parent language.

I hope someone talented will build one of these for C/C++. Mobile an game
developers could use it.

~~~
anonymoushn
Luajit already enjoys performance in the ballpark of native code. As far as I
know, mobile and game developers do use it.

~~~
stephth
Lua is fast as scripting languages go, but saying it's in the same performance
ballpark as native code is a stretch [1]. Game developers that use Lua
commonly rely on C/C++ for low level routines.

There's a space for innovation there. ooc [2] has been a step in that
direction, although its usage of garbage collection makes it much less
flexible than CoffeeScript or MoonScript. I don't think developers need to be
abstracted from memory management at low level. What they could use is getting
rid of a lot of cruft, to be able to write/read/think more quickly.

[1] <http://attractivechaos.github.com/plb> [2] <http://ooc-lang.org/>

------
svdad
Still don't understand the fad for "programmer-friendly" languages. Why on
earth would you even start learning to program if you didn't find something
diabolically fascinating about learning a new syntax for symbolic computation?

C, C++, APL, etc. all seem perfectly "programmer-friendly" to me, once you've
learned them...

------
wsxiaoys
Wow, i've asked this before,
[http://www.reddit.com/r/coffeescript/comments/hmtjv/what_abo...](http://www.reddit.com/r/coffeescript/comments/hmtjv/what_about_implement_a_lua_backend_for/)

Really happy to see some action!

------
Herald_MJ
Lua isn't programmer friendly?

~~~
walrus
No one said it wasn't. The author claims that MoonScript is programmer
friendly, but he never said that Lua isn't. It's an alternative, but not
necessarily an improvement.

------
clyfe
There's also this effort <https://github.com/CDR2003/coffee-script-lua> don't
know how far it reached tough.

------
blackRust
The first thing I do is click on the 'Lua' link. <http://ww.lua.org> Really?
Please fix.

------
z92
The next time I need to code in C, I shall try moonscript first. Thanks author
for this great piece of software.

------
vjeux
<http://moonscript.org/reference/#considerations>

    
    
        b = x-10
        is converted to
        local b = x(-10)
    

This looks like to be really error prone.

------
malkia
That looks very cool!

------
nknight
Some of this is a definite improvement over Lua, but I'm getting really tired
of some of these cute little syntaxes showing up everywhere, like '->' and
'=>' for creating functions, and what's with this:

 _! operator can be used to call a function with no arguments_

Seriously?

I feel like people are coming up with these things just to be "different".
Programming language syntax is a UI, and needs to be treated like one -- you
don't make major changes to basic UI paradigms without convincing reason.

Edit: Maybe more to the point, you don't add random buttons to a UI that do
non-obvious things. Language syntax should be self-evident and quickly
readable, and shouldn't require careful parsing of individual characters.

~~~
thurn
What's the fun of that? Playing with new syntax ideas is the whole point of
language creation.

~~~
nknight
If this were somebody's toy or research language, I wouldn't be complaining,
but when a language is clearly being marketed as something people would want
to use in the real world, I expect it to be based on real evidence and real
experience, not just somebody playing around.

~~~
squarecog
Where did you get that this is being marketed for production? Did you just
assume that because the site looks nice?

Handy tip: languages that are marketed for use in the real world tend to
advertise actual uses in the real world.

~~~
stephth
Why wouldn't this be used for production? It compiles to human readable Lua.

~~~
anonymoushn
I'm not sure that copy and pasting class.lua for every class definition makes
for human readable Lua.

~~~
stephth
It's human readable as far generated code goes. It's not always practical to
read (specially with classes), but you can if you have to. It's one of the
philosophies behind CoffeeScript. As you can see its translation of OOP is
verbose too, but readable [1], and the verbosity of the generated code is
balanced by the power added on the CoffeeScript side.

My point/question was: it doesn't add a runtime or new libraries/routines, you
can read the generated code if something goes wrong, so why wouldn't it be ok
to use in production?

[1] <http://jashkenas.github.com/coffee-script/#classes>

------
hackinthebochs
I will be extremely happy when the whitespace-for-blocks fad passes. I have a
feeling it's going to be a long winter.

