Live data from Hacker News

MoonScript, a programmer friendly language that compiles to Lua

moonscript.org

111–120 of 171 posts

Re: MoonScript, a programmer friendly language that compiles to Lua

#111

Earlier quoted context omitted.

I see it as a toy language. The only person I think would find it useful is leafo himself since he can edit it however he wants. But everyone else should stay away from it. Plain Lua is so much better.

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 - i…

> 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

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

Re: MoonScript, a programmer friendly language that compiles to Lua

#112

Earlier quoted context omitted.

The list comprehensions are really great. Most of the time when I'm writing Lua I can't be bothered to write exactly what Moonscript outputs for a list comprehension because it's noisy, but it's what I really would write if I cared about tiny amounts of performance.

Idk. Still not sold. You can do list comprehensions in regular Lua with something like this: function listcomp(t, f) local r = {} for k,v in pairs(t) do r[k] = v end return r end And then, your Lua code would be like: listcomp({1, 2, 3, 4}, function(k, v) return v*2 end) Which would be the equivalent to this in MoonScript: [v*2 for k,v in pairs({1, 2, 3 ,4})] I dunno. Just seems like a wash to me. And then you think…

Over here it generated

  local b
  do
    local _accum_0 = { }
    local _len_0 = 1
    for k, v in pairs({
      1,
      2,
      3,
      4
    }) do
      _accum_0[_len_0] = v * 2
      _len_0 = _len_0 + 1
    end
    b = _accum_0
  end
It did a pretty good job. Unlike your code, it doesn't have any function calls, and unlike the code I would probably write, it doesn't use the # operator.

Re: MoonScript, a programmer friendly language that compiles to Lua

#113

Earlier quoted context omitted.

The list comprehensions are really great. Most of the time when I'm writing Lua I can't be bothered to write exactly what Moonscript outputs for a list comprehension because it's noisy, but it's what I really would write if I cared about tiny amounts of performance.

Idk. Still not sold. You can do list comprehensions in regular Lua with something like this: function listcomp(t, f) local r = {} for k,v in pairs(t) do r[k] = v end return r end And then, your Lua code would be like: listcomp({1, 2, 3, 4}, function(k, v) return v*2 end) Which would be the equivalent to this in MoonScript: [v*2 for k,v in pairs({1, 2, 3 ,4})] I dunno. Just seems like a wash to me. And then you think…

There are no potential performance hits. In particular the code generated for list comprehensions would be faster than your example because there is no extra function call per item.

Re: MoonScript, a programmer friendly language that compiles to Lua

#114

Earlier quoted context omitted.

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 - i…

> 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 > 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({},…

>

    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).

Re: MoonScript, a programmer friendly language that compiles to Lua

#115
post #83

Some of the stuff in Moonscript feels a little overdone and magical, like parens-less function calls and the syntactically significant whitespace - but others really feel like they're fixing the gaps in Lua. Moonscript's nice lambda syntax, ternary operator, default local, implicit return, etc. But I don't think I really needed the ! operator, for example.

fixing the gaps in Lua. Moonscript's [...] default local Roberto Ierusalimschy, the creator of Lua, believes that "Local by default is wrong." [1]. I don't necessarily agree that local-by-default is inherently wrong, but every implementation of local-by-default that I've seen has had flaws. It looks like MoonScript is no different - its scoping rules seem to suffer from the same "madness" as CoffeeScript [2]. [1] htt…

Eugh, I know you aren't defending that CoffeeScript article, but it hugely exaggerates the 'problem' by not acknowledging module scope (see the comments).

Re: MoonScript, a programmer friendly language that compiles to Lua

#116

Earlier quoted context omitted.

I was just looking at love2d, I don't know much about it. My son is 8 and is very bored with Scratch. A once over the documentation makes me think love2d might be a good fit for a next step from Scratch. How is the love2d community and is it active?

The love2d community is definitely still active, especially on IRC. Some of the nicest folks I've ever spoken to over the internet. I can't recommend the language or its community highly enough.

A couple of friends just successfully launched a commercial game on android/ios/steam using love2d, and they're really happy with the results.

I couldn't believe it was made with lua, it runs really smooth.

http://midipixel.com/warlockstower/

Re: MoonScript, a programmer friendly language that compiles to Lua

#117
post #15

Hey all, I made MoonScript about 6 years ago. I used it to build a ton of opensource stuff in addition to the company I founded. I use it every day and I'm very happy with how it's turned out. I regret not updating the language more frequently, but I've been busy building a bunch of stuff in it. The biggest open source project is a web framework for Open Resty: https://github.com/leafo/lapis It's used for the followi…

This post was timely for me as I'm working on a game project that could benefit greatly from each of the projects you mentioned. Thanks!

Re: MoonScript, a programmer friendly language that compiles to Lua

#118
post #94

Earlier quoted context omitted.

Yes there are many algorithms that are naturally 0 indexed. But there are also many that are naturally 1 indexed! This is somewhat unscientific, but I once went through the first quarter of an algorithms textbook. And counted how many were naturally one based or zero based. And on most it didn't matter, but there were slightly more one based ones.

Can you give us some examples of one-based algorithms? I've done a lot of programming in one-based languages, and now avoid such languages as much as possible (sometimes have no choice) because nothing seems to naturally fit into that.

any kind of numerical method (RKs, FDs, CN) where the n-th step a_n = f(a_(n-1)) and hence you define NUM_STEPS and the the result is a[NUM_STEPS] where a is your numerical lattice.

you could work in a 0-based index and your n-th step is a_(n-1) and so the final step is a[NUM_STEPS - 1]

in numerical analysis I don't believe i've ever cared that much about slicing. if i wanted to look at a single element in a matrix a_(ij), then I call the matrix a[i,j]. if you had to implement a pivoting algorithm then it's quite useful to call the pivot element a[i,j] and pivot row a[i,:]. i believe most devs would prefer not to have to call elements everytime a[i-1,j-1].

guessing most math guys have worked with both 0 and 1 systems and honestly don't care that much.

Re: MoonScript, a programmer friendly language that compiles to Lua

#119

Earlier quoted context omitted.

Are you aware that TIC-80 supports moonscript? It's one of the better PICO-8 "clones" out there. https://nesbox.itch.io/tic https://github.com/nesbox/tic.computer/wiki#cartridge-metada...

Is that open source? I'm wondering if it uses SDL or a similar library - binaries look pretty small.

A similar project, uses SDL, is open source, and came from antirez (of redis fame), LOAD81:

    http://github.com/antirez/load81.git

Re: MoonScript, a programmer friendly language that compiles to Lua

#120
post #110
post #15

Hey all, I made MoonScript about 6 years ago. I used it to build a ton of opensource stuff in addition to the company I founded. I use it every day and I'm very happy with how it's turned out. I regret not updating the language more frequently, but I've been busy building a bunch of stuff in it. The biggest open source project is a web framework for Open Resty: https://github.com/leafo/lapis It's used for the followi…

I have to say that if I see last update in changelog from few years ago I assume the project is dead and one should not use it.

You should disabuse yourself of this notion, a lot of mature projects don't get updates because they don't have (known) bugs or are feature complete.
Post reply on HN