by Leaf Corcoran
A programmer friendly language that compiles to Lua.

MoonScript provides a clean syntax using significant whitespace that avoids all the keyword noise typically seen in a Lua script.

It also adds table comprehensions, implicit return on functions, classes, inheritance, scope management statements import & export, and a convenient object creation statement called with.

It can be loaded directly from a Lua script without an intermediate compile step. It even knows how to tell you where errors occurred in the original file when they happen.

-- an implementation quick sort using comprehensions

items = {4, 5, 2, 1, 3, 8, 9, 0}

-- append array tables
concat = (...) ->
  out = {}
  for t in *{...}
    table.insert out, i for i in *t
  out

format = (t) ->
  print table.concat t, ", "

quicksort = (items) ->
  return {} if #items == 0
  pivot = items[1]
  rest = [i for i in *items[2,]]
  concat quicksort([i for i in *rest when i < pivot ]),
    {pivot},
    quicksort([i for i in *rest when i >= pivot])

format quicksort items
Information updated 06/06/13
View Comments