This blog post is several years old at this point, but it recently came up on hacker news. The short version: Experienced C++ programmer decides C++ is too heavyweight, and the core abstractions suck, starts working on generating C with lisp macros. I’ve had this idea myself.
The idea of macros on top of a low-level language seems to have a few other independent inventors as well:
Rust has a macro system too, for that matter.
Syntactic, compile time abstraction in a low-level language still seems promising to me, but I’m somewhat skeptical of the exact approach that the author of the original post and I took. There are a few reasons for my skepticism:
- When I’m doing something as dangerous as C programming, I want a type system at my disposal. The macro system idea has me working heavily at a meta-level that doesn’t have types, even if the output format does. There are probably some clever things you could do here, but trying to do type checking in a syntax-oriented abstraction mechanism seems prone to error
- With things like LLVM out there, it seems silly to plumb what is essentially a new language through a C compiler. You’ll end up with annoying limitations, and irrelevant details to worry about. Even the actual formatting as C is irritating to write, mostly because C’s syntax for types is absolute garbage — though that at least only needs to be done once.
I abandoned my version of this project a while ago, and it’s interesting to look back on it with a new perspective. I’m not likely to pick it up again any time soon, but if I did it would probably look a bit different. My first instinct is to make a Haskell library of combinators that generate LLVM code, or something similar.