2 ms·
Yes absolutely! I've long been interested in multi-stage programming for this reason. Oil is filled with this pattern: do a bunch of metaprogramming at startu
by chubot 9y ago
Yes absolutely! I've long been interested in multi-stage programming for this reason.
Oil is filled with this pattern: do a bunch of metaprogramming at startup to make some data. Then use that immutable data for the rest of the program. There are very much two stages.
I think Lua-Terra might be closest to the thing I want, although I haven't had a chance to play with it:
http://terralang.org/ http://terralang.org/
I mention Bob Nystrom's language Magpie, which has an interesting model. Do the type checking at main(), not after parsing! But everything that happens before main(), at import time, is metaprogramming!
A Problem with Type Checking http://www.oilshell.org/blog/2016/11/30.html http://www.oilshell.org/blog/2016/11/30.html
I think I want to do compilation/optimization right before main(), not just type checking. It's all a bit vague right now, but I think OPy can go in this direction. Having the compiler written in its own language facilitates this. You can run code first, and then compile.
This post is also related:
Type Checking vs. Metaprogramming; ML vs. Lisp http://www.oilshell.org/blog/2016/12/05.html http://www.oilshell.org/blog/2016/12/05.html
Also note that C++ is a two-stage language too. In fact Herb Sutter just proposed that they unify the two languages. Like you can use STL with constexpr at compile time. Link on this page:
https://github.com/oilshell/oil/wiki/Metaprogramming https://github.com/oilshell/oil/wiki/Metaprogramming
I think your suggestion is exactly what I've been thinking, so if you want to talk more about it / work on it, feel free to mail me :) The code needs a bit of work but I think it's a promising direction.