The macro will slurp `if debug: true else: false` as expression. It will not be
resolved; instead, inside the macro, you will have this whole expression in
your variable `debug`.
> Is there a way to 'extract' the boolean value of (the identifier) debug in
> the macro
It does not have a value when the macro is executed. The macro is executed at
compile-time. The `debug` in `main()` is a `let` variable, i.e. is set at
run-time. The macro cannot possibly know its value when it executes, because it
isn't set yet.
> The macro I'm messing with is the body of a loop that gets executed many
> times; while I can make it a simple procedure, the performance goes down
> considerably.
It seems like you want to use a simple template instead:
template dumbMacro(debug: bool = false): typed =
if debug:
stderr.writeLine "DEBUG ON"
echo "Hello from dumbMacro!"
proc main() =
let debug = "-d" in commandLineParams()
dumbMacro debug
when isMainModule:
main()