4

I have a line of code that I want to run in debug mode but not in release mode. Is there a way to automatically handle this?

Imran
  • 12,950
  • 8
  • 64
  • 79

1 Answers1

9
when not defined(release):
  echo "Debug"

Compiler options set with -d, like -d:release, can be used in the program using the defined proc: https://nim-lang.org/docs/system.html#defined,untyped

Since it's available at compile-time we can use a when (compile-time if) instead of a regular runtime if.

def-
  • 5,275
  • 20
  • 18