Re:MoonScript, a programmer friendly language that compiles ...
by RyanSquared on Monday May 29, 2017 @05:52PM
(#14441675)
This is basically Lua, excluding type annotations. Lua's form of OOP is very strange in that methods aren't bound to a parent context, but instead take the object as a value. For example, `object:method()` is the same as `object.method(object)`, and `function object:method()` is the same as `function object.method(self)` - the only difference being calling the function via `object:method()` is a bit more optimized. There is also a framework with networking, signals, and other cool features called `cqueues` which works based off of coroutines.s You might want to check that out too :)
Re:MoonScript, a programmer friendly language that compiles ...
by Cyph0n on Monday May 29, 2017 @05:57PM
(#14441698)
And the size of the Lua runtime is nothing short of beautiful. I have yet to find a use for Lua though, so I'm still waiting for an opportunity to work on something with it.
Re:MoonScript, a programmer friendly language that compiles ...
by RyanSquared on Monday May 29, 2017 @06:00PM
(#14441720)
I find it's used a lot in places you wouldn't expect. I found it used in a car radio, the modem used in my house, and a few other places. It's lightweight if you want to use it on embedded systems (for example, NodeMCU) if you're into that kind of thing.
Re:MoonScript, a programmer friendly language that compiles ...
by wcummings on Monday May 29, 2017 @06:26PM
(#14441829)
Iirc its used on some digital cameras as well.
Re:MoonScript, a programmer friendly language that compiles ...
by spc476 on Monday May 29, 2017 @11:24PM
(#14442850)
I'm using it at work to parse SIP messages (with LPeg) for one of our customers (one of the cellphone carriers). Between LPeg for parsing, and coroutines in Lua, the code is pretty easy to read and follow.
Re:MoonScript, a programmer friendly language that compiles ...
by weberc2 on Monday May 29, 2017 @07:44PM
(#14442122)
I forgot to emphasize that I'm particular about syntax. I amended my comment accordingly. I also don't like the global-by-default bit, but maybe my ideal language could be a syntax layer atop Lua?
Re:MoonScript, a programmer friendly language that compiles ...
by rweichler on Monday May 29, 2017 @08:27PM
(#14442291)
Metatables are your friend.
-- LuaJIT
local oldG = _G
local newG = setmetatable({}, {
__index = oldG,
})
setmetatable(oldG, {
__index = function(t, k)
return rawget(newG, k)
end,
__newindex = function()
error('attempt to assign global variable')
end,
})
_G = newG
If you want to assign a global variable, `x = 5` will error but `_G.x = 5` won't.
Re:MoonScript, a programmer friendly language that compiles ...
by vanderZwan on Tuesday May 30, 2017 @02:54AM
(#14443355)
If you ignore the class support of moonscript, you can pretty much use it to do what you want. It doesn't have the "global by default" silliness, to start with.
Re:MoonScript, a programmer friendly language that compiles ...
by rattray on Tuesday May 30, 2017 @02:14AM
(#14443231)
That actually wouldn't be hard to make; just use a custom eslint rules!
If you want implicit returns and really want to disable "fancy features", babel plugins are fairly easy to create – blacklisting certain constructs wouldn't be very difficult, and implicit returns aren't so hard (you can copy my implementation[0] from a JS superset I built called LightScript[1]).
EDIT: bonus of building on babel is that you can get static types for free à la Flow (though typechecking implicit returns may be a pain).
[0] - https://github.com/lightscript/babel-plugin-lightscript/blob...
[1] - http://lightscript.org
Re:MoonScript, a programmer friendly language that compiles ...
by weberc2 on Tuesday May 30, 2017 @10:14AM
(#14445495)
Very cool! I can live without implicit returns. Thanks for the info!
Re:MoonScript, a programmer friendly language that compiles ...
by kuiper83 on Monday May 29, 2017 @05:57PM
(#14441697)
Clojure [1] seems to meet all of these criteria. It's a functional language where you can get away with using only a few data types, while also supporting (most of) the rest of the things you mention.
Re:MoonScript, a programmer friendly language that compiles ...
by weberc2 on Monday May 29, 2017 @07:39PM
(#14442101)
I like the idea, but I want it to be embeddable and since I'll mostly be embedding this in some syntactically C-like language, I would like the scripting syntax to not look so out of place. I updated my previous post to say as much.
Re:MoonScript, a programmer friendly language that compiles ...
by shalabhc on Monday May 29, 2017 @09:36PM
(#14442516)
Moonscript uses local by default (compiles to Lua). Here is your code in Moonscript:
foo = {
x: {1, 2, 3},
y: (a, b, c) ->
sum = a + b + c
sum * sum
}
Re:MoonScript, a programmer friendly language that compiles ...
by weberc2 on Monday May 29, 2017 @10:34PM
(#14442711)
Yeah, now just strip away all the other stuff and we'll be good.
1. Lists and objects/dicts only; objects have no prototypes at all; objects have no first-class methods, but they can have functions as member variables, and those functions can close over other data in the object
2. All function and variable declaration is anonymous (as a consequence of 1); if you want to define a schema for an object, build a function that takes certain arguments and returns an object with the corresponding structure.
3. Coroutines/fibers/etc for async things; no promise/callback hell
4. Type annotations a la Python (not sure how this fits with 2 just yet)
EDIT: I did a bad job of emphasizing this, but syntax is important to me--I want something that looks like:
Whether or not you agree that syntax should be a relevant criteria is a different matter. :)