Hacker News new | ask | show | jobs
by Guthur 4577 days ago
I think you might have missed the point of the statement "programs that write programs", it goes far beyond a toy quine.

You can't do it in C unless you also implement a compiler or evaluator. And even then generating any sort of reasonably complex C code with C would be highly painful to say the least.

You can possibly nearly get there with C macros but I would argue it's not C writing C there, rather a text preprocessor.

1 comments

> You can't do it in C unless you also implement a compiler or evaluator.

Someone else already did that work. Your C compiler is very likely, in fact, already written in C. We don't expect a C-importable library interface for the C compiler, because none of the traditional old C compilers had one (gcc, MSVC, etc.) But libclang exists, and it's pretty easy to write a C REPL using it. From there, only a few steps to automation.