Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Metalua isn't compatible with luajit. It needs the slower C based interpreter. Its problem was that it was based on a very old version of Lua and it needed things like goto that weren't in lua yet, so it goes straight to bytecodes.

I'm working on building languages on top of Lua/Luajit, since Lua has a good tracing jit, there's no reason you can't write an expanded metalanguage on it that will preprocess a bit and give you a brand new language.

By the time I'm done it will have the power of scheme (including continuations, with some functions compiled internally to use continuation passing style, since Lua guarantees tail call elimination) and macros. The main difference should be that the base type will be arrays and tables not lists, but that could be an improvement. I'll probably tack on something like s-expressions too.



You should find this interesting http://terralang.org

Took me a couple reads to figure out what it does. Luajit is the metalanguage for Terra. But, if you want to, you can run a mixture of Lua and Terra at runtime or statically compile to a pure Terra exe or .o with no Lua runtime at all.


that reminds me a bit of lush [http://lush.sourceforge.net/], one of a small handful of languages that i really feel should have made the jump to at least haskell-level popularity.

hn actually had a lush discussion recently: https://news.ycombinator.com/item?id=9602430


Also, I've worked in both Lua and Racket.

Racket's garbage collector is the only one I've ever used that actually made programs unusable.

Also, Racket's macro system feels like a mistake. While it's more powerful than most others, it's still rather incomplete, feels like a bad design, and ... well just look at the code that's used to implement the (sadly slow) object system. The code makes assembly language look clear by comparison. Dig under the surface and despair.

Scheme is very powerful, but in the end Lua programs are a lot more readable.


[edit, I wrote this before you changed your comment so say "one-shot". In short my continuations are not one shot, they are delimited though, by necessity because I don't rewrite ALL functions into continuation passing style, and you can't recast what lua calls metafunctions.]

Continuations are not coroutines.

Continuations let you save the current position, like setjump/longjump. But unlike setjump/longjump you can continue inside a function that already returned, ie as long as there is a continuation remembering that position then the activation record can't be deleted.

That means that activation records (ie local variables) can't be just the top of the stack - it changes things deep.

Also note that continuations only save the position, they don't restore the values of variables to what they were at that position, so re-evaluating continuation more than once will break any code that wasn't expecting to re-run.

Something that snapshots some local variables as well as the position will be more useful than raw continuations for things like search, backtracking, and logical programming languages.

[edit 2, I am ALSO adding snapshot continuations for these purposes]

Running an OUTER continuation rather than an inner one looks like an exception.


Doesn't Lua already have (one-shot) continuations, in the form of coroutines?


> Metalua isn't compatible with luajit.

Although there should not be any obstacles for porting (or re-implementing) MetaLua on top of the most modern luajit.

> The main difference should be that the base type will be arrays and tables not lists, but that could be an improvement.

That should only matter in compile time anyway, for your meta-language. Target may use whatever data structures you want.

> I'll probably tack on something like s-expressions too.

It's not necessary for a meta-language, as long as you have quasiquotation (that works both for constructing ASTs and for pattern-matching them). It's just the easiest way, but not the only one.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: