7 ms·
MoonScript - A programmer friendly language that compiles to Lua.
- malkia 15y agoThat looks very cool!
- clyfe 15y agoThere's also this effort https://github.com/CDR2003/coffee-script-lua https://github.com/CDR2003/coffee-script-lua don't know how far it reached tough.
- gmac 15y agoAlmost 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 15y agoIndeed. 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 )
- Cushman 15y agoJust in case anyone else misread this— the comment symbol in MoonScript is literally `--`.
- stephth 15y ago-- is the Lua syntax for comments. I'm curious about why the author kept it.
- jacques_chester 15y ago... because it works fine?
- ColinWright 15y agoAre 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_languages_%28syntax%29#Comments http://en.wikipedia.org/wiki/Comparison_of_programming_langu... 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 "--".
- squarecog 15y agoCoffeeScript. CS. JavaScript. JS.
- clyfe 15y agoby CS I mean CoffeeScript, sorry about ambiguity
- Cushman 15y agoBut 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.
- Cushman 15y agoWow, yeah. I wouldn't complain personally, since I love CoffeeScript syntax, but it is pretty odd that it's not mentioned at all. Edit: As seen above, it's mentioned now, so I'm happy :) It's still a little irritating that they've changed things that CS handles quite elegantly to be less expressive, presumably just out of a desire to be different. I understand changes to the syntax are necessary for various reasons, but something like ! for argumentless function calls instead of () just seems like needless divergence. Was that extra character really killing you? Is the confusion with other meanings of ! really worth it?
- ColinWright 15y agoAt the bottom of the page (which you can get to by clicking on "About") it says: About The syntax of MoonScript has been heavily inspired by syntax CoffeeScript.
- leafo 15y agoHi, I'm the author. You're right about the resemblance to CoffeeScript. I added some recognition at the bottom. Thanks for pointing it out, I just got the site up within the last hour so there are still finishing touches to be made.
- evanlong 15y agoAre you the same leafo that founded apedick.com? You are my hero.
- bakineggs 15y agoIt always seemed like you were a fan of leaf's ape dick. :P
- candeira 15y agoI am curious about why didn't you just implement the CoffeeScript syntax outright? Learning just one syntax would make it easier for people wanting to deploy to JavaScript and to Lua. Imagine that C on the PDP-11 had a slightly different syntax from C on x86, and the syntax were different from that on C on ARM, etc.
- nknight 15y agoSome 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 15y agoWhat's the fun of that? Playing with new syntax ideas is the whole point of language creation.
- nknight 15y agoIf 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 15y agoWhere 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 15y agoWhy wouldn't this be used for production? It compiles to human readable Lua.
- 15y ago
- aashay 15y agoAnybody try writing an iPhone app with MoonScript -> Lua -> Wax -> Objective C?
- chriseidhof 15y agoExactly! 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 15y ago> Exactly! I think they only need some kind of way to add syntax for obj-c style messages. http://olua.sourceforge.net/ 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.
- jacques_chester 15y agoI 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 15y agoI 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 15y agoI 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 15y agoI 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.
- neworbit 15y agoVery 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!
- blackRust 15y agoThe first thing I do is click on the 'Lua' link. http://ww.lua.org http://ww.lua.org Really? Please fix.
- stephth 15y agoThis 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 15y agoLuajit already enjoys performance in the ballpark of native code. As far as I know, mobile and game developers do use it.
- stephth 15y agoLua 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 http://attractivechaos.github.com/plb [2] http://ooc-lang.org/ http://ooc-lang.org/
- Herald_MJ 15y agoLua isn't programmer friendly?
- walrus 15y agoNo 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.
- wsxiaoys 15y agoWow, i've asked this before, http://www.reddit.com/r/coffeescript/comments/hmtjv/what_about_implement_a_lua_backend_for/ http://www.reddit.com/r/coffeescript/comments/hmtjv/what_abo... Really happy to see some action!
- skrebbel 15y agoIn 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.
- v21 15y agoLua wins for in-game scripting and embedded devices. In these places, it's Lua, or hacking onto the C/C++ engine/framework code. Or, now, MoonScript with some extra fuss. Mind, Lua isn't terrible, so I think I'd stick to Lua and avoid the fuss. But others will disagree.
- silentbicycle 15y agoIt'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 15y agoIt 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.
- ukaszg 15y agoAlso Moonscript is difficult to read (at least compared to Lua). If you miss OO in Lua, use some OO library (I like middleclass). Honestly, I don't see any gain in Moonscript.
- wildmXranat 15y agoIf 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 15y agoNot 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 15y agoIt'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.
- silentbicycle 15y agoLua's compiler adds very little overhead, compared to loading directly from luac's precompiled bytecode. It has a really fast, single pass compiler, which is optimized for reading in data serialized as Lua tables. Lua was designed with JSON-like use cases in mind. Its compiler doesn't do much analysis / optimization, but the performance of individual Lua constructs is usually easy to reason about.
- hxa7241 15y ago'Lua bytecode' does not really exist -- i.e. it has no public definition -- the developers can change it in any way at any time -- only the Lua language itself is 'defined'.
- strmpnk 15y agoWhat's the point of locking yourself to a bytecode when Lua code JITs just fine on LuaJIT? Lua is a great language and this looks like another alternative. I doubt we're looking at exclusion here.
- deleted 15y ago[deleted]
- z92 15y agoThe next time I need to code in C, I shall try moonscript first. Thanks author for this great piece of software.
- hackinthebochs 15y agoI will be extremely happy when the whitespace-for-blocks fad passes. I have a feeling it's going to be a long winter.
- deleted 15y ago[deleted]
- vjeux 15y agohttp://moonscript.org/reference/#considerations http://moonscript.org/reference/#considerations b = x-10 is converted to local b = x(-10) This looks like to be really error prone.
- rbxbx 15y agoThe killer feature of MoonScript would be 0 based indexes. See no mention of it though...
- svdad 15y agoStill 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...