3 ms·
There are a lot of features that make Moonscript much more convenient than plain Lua. Examples (try the first three in Lua): - default values for function para
by shalabhc 9y ago
There are a lot of features that make Moonscript much more convenient than plain Lua. Examples (try the first three in Lua):
- default values for function parameters
- list comprehensions
[x * 2 for x in *{1, 2, 3}]
- easier iteration (e.g. `for key, value in pairs obj`)
- local is default, not global
- a simple class system if you need it
- `export`, `from` and `import` keywords
- `+=`, `/=`, `*=` etc. operators
- indentation based scope (ok, this is debatable)
I can't think of a single place where plain Lua is actually better. OK maybe `:` is better as a method call operator, but that's it.
- rweichler 9y ago> default values for function parameters function f(a, b, c, d) a = a or 1 b = b or 2 c = c or 3 d = d or 4 end > list comprehensions https://news.ycombinator.com/item?id=14444215 https://news.ycombinator.com/item?id=14444215 > local is default, not global I think this is a con. > a simple class system if you need it I also think this is a con, because it limits flexibility. Here's my class system: Object = {} function Object:new() local self = setmetatable({}, {__index = self}) return self end And how to use it: local super = Object Shape = Object.new(super) function Shape:new(color) local self = super.new(self) self.color = color return self end local super = Shape RedShape = Object.new(super) function RedShape:new() local self = super.new(self, 0xff0000) return self end If I want to add multiple inheritance, or interfaces, it is easy. Because it is just metatables. With MoonScript this is not possible. > `export`, `from` and `import` keywords Sounds like a con to me. `require` is simple. > `+=`, `/=`, `*=` I agree with this one.
- shalabhc 9y ago> function f(a, b, c, d) a = a or 1 b = b or 2 c = c or 3 d = d or 4 end Compare with: f = (a=1, b=2, c=3, d=4) -> ... Also note the latter is correct when you call it as f(false).