5 ms·
I've just started storing metadata in JSON format. Then, I have a cmake target that invokes a python program that reads in the JSON and generates .h/.cpp files
by umvi 7y ago
I've just started storing metadata in JSON format. Then, I have a cmake target that invokes a python program that reads in the JSON and generates .h/.cpp files which can then be consumed by other targets.
The advantage of this is that I can then use the same metadata JSON to generate documentation, or whatever I want.
- reikonomusha 7y agoHave you learned about Lisp macros yet? If you’re intrigued by this idea, Lisp macros are a few steps above in terms of functionality, integration, etc.
- TylerE 7y agoOr nim, which is even more powerful
- discardable_dan 7y agoFirst, can you talk a little about how Nim's macro system is more-powerful than Lisp's? That seems like a fairly broad claim, and unless it allows you to influence the compiler at compile time (and maybe even then), I am curious how that works out. Second, one of the biggest issues with lisp is that macros end up sort of slow, especially when you're using them + lists to replicate ADTs with pattern matching (versus, say, ML, which can do very fast dispatch based on types). Doesn't Nim fall into that same trap?
- TylerE 7y agoIt can do absolutely everything lisp macros can do, with more flexible input syntax, and zero runtime overhead, while being both strongly typed and giving the macro body access to the types (PS: Lisp fanboys downvoting this, how about attempting to make a counterargument instead of just hitting the downvote button?)
- emidln 7y agoLisp macros have runtime overhead? I don't think reader macros or compile macros have any runtime overhead unless you add it yourself. More flexible input syntax than a programmable reader? Data like sexps and edn is pretty flexible to begin with, but a lot of lisps have fully programmable readers for arbitrary syntax. Some lisps even support grammar dialects to switch out of sexps entirely (such as racket).
- TylerE 7y agoNim macros operate directly on the ast while providing flexible user friendly (read: not sexp) calling syntax. Everything is fully typed, and the types are available to the macro expansion. Absurdly powerful things have been done, for instance https://github.com/krux02/opengl-sandbox https://github.com/krux02/opengl-sandbox which crosscompiles nim to GPU shaders.
- ori_b 7y agoIt's like you didn't read the previous poster: They're claiming lisp macros can work BEFORE the compiler generates an AST.
- TylerE 7y agoYes, it's the same in nim. For instance, see this example which defines a compact definition syntax that is certainly not valid vanilla nim: https://peterme.net/metaprogramming-and-read-and-maintainability-in-nim.html https://peterme.net/metaprogramming-and-read-and-maintainabi... Refer to lines 63-88 of the large final example.
- ori_b 7y agoAnd if I wanted to make 'for' into a valid variable name, or change the tokens for specifying numbers, for example, how would I go about doing that?
- umvi 7y agoAre you talking about using Lisp macros to generate C/C++/documentation? I'm not sure how Lisp macros would be better than static metadata files being operated on by some high level scripting language.
- reikonomusha 7y agoThe author created a DSL which generates code. Macros are another way to do that.
- acchow 7y agoSo your template metaprogramming is itself generated?
- umvi 7y agoI'm guessing this is a joke, but in case it's not - sure, technically you could generate template metaprogramming with an additional layer of metaprogramming as I've described. But since you already have metaprogramming at the higher level, there is not as much need for template metaprogramming IMO