4 ms·
> How do you people debug and test these meta programs? I couldn't find any other answer than using @compileLog to print-debug [1]. In lisp, apparently some im
by benob 2y ago
> How do you people debug and test these meta programs?
I couldn't find any other answer than using @compileLog to print-debug [1]. In lisp, apparently some implementations allow to trace macros [2]. Couln'd find anything about Nim's macro debugging capabilities.
This whole thing looks like a severe limitation that is not balanced by the benefit of having all code in the same place. Do you know other languages that provide sensible meta-programming facilities?
[1] https://www.reddit.com/r/Zig/comments/jkol30/is_there_a_way_i_can_debug_comptime_code/ https://www.reddit.com/r/Zig/comments/jkol30/is_there_a_way_...
[2] https://stackoverflow.com/questions/44872280/macros-and-how-to-trace-them https://stackoverflow.com/questions/44872280/macros-and-how-...
- disentanglement 2y agoIn lisp, macros are just ordinary functions whose input and output is an AST. So you can debug them as you would any other function, by tracing, print debugging, unit tests or even stepping through them in a debugger.
- michaelsbradley 2y agoTo debug macros in Nim, you'll likely need to print arguments and expansions at compile-time, inspect the output, change things to see what happens, repeat... https://nim-lang.org/docs/macros.html#toStrLit%2CNimNode https://nim-lang.org/docs/macros.html#toStrLit%2CNimNode https://nim-lang.org/docs/macros.html#astGenRepr%2CNimNode https://nim-lang.org/docs/macros.html#astGenRepr%2CNimNode https://nim-lang.org/docs/macros.html#dumpAstGen.m%2Cuntyped https://nim-lang.org/docs/macros.html#dumpAstGen.m%2Cuntyped https://nim-lang.org/docs/macros.html#treeRepr%2CNimNode https://nim-lang.org/docs/macros.html#treeRepr%2CNimNode https://nim-lang.org/docs/macros.html#dumpTree.m%2Cuntyped https://nim-lang.org/docs/macros.html#dumpTree.m%2Cuntyped https://orlybooks.com/books/changing-stuff-and-seeing https://orlybooks.com/books/changing-stuff-and-seeing