When working on compile time features it would be nice to echo
something at compile time. If an echo
is withing a macro it is already executed at compile time. But is it also possible to print something at compile time e.g. from the global scope? I'm looking for a function like echoStatic
in this:
echoStatic "Compiling 1. set of macros..."
# some macro definitions
echoStatic "Compiling 2. set of macros..."
# more macro definitions
There is no need for a special echoStatic
. This is solved by the general solution of running code at compile time, which is to use a static
block:
static:
echo "Compiling 1. set of macros..."
# some macro definitions
static:
echo "Compiling 2. set of macros..."
# more macro definitions
In languages like C, C++ and D, you can typically use a pragma for this job. This also works for Nim:
from strformat import `&`
const x = 3
{. hint: &"{$typeof(x)} x = {x}" .} # <file location> Hint: int x = 3
It also prints the file, the line and the column which can be useful for compile-time debugging.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With