3 ms·
Nim macros operate directly on the ast while providing flexible user friendly (read: not sexp) calling syntax. Everything is fully typed, and the types are ava
by TylerE 7y ago
Nim 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?
- junke 7y agoOk this is nice but you this would be rougly the same in Lisp, apart from AST constructors ("newIdentNode()",...), which would simply be backquote/unquote. Plus you have to write enumInfo[0], enumInfo[1] instead of pattern matching.