4 ms·
Lisp 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 synt
by emidln 6y ago
Lisp 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 6y 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 6y agoIt's like you didn't read the previous poster: They're claiming lisp macros can work BEFORE the compiler generates an AST.
- TylerE 6y 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 6y 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 6y 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.