在编译时运行Nim代码

Sam*_*adi 4 dry compile-time nim-lang

所以我知道如果我定义一个constNim会评估我在编译时分配给它的任何东西,所以我可以这样做:

proc compileTimeCode: bool =
  # Put code here
  return true

const _ = compileTimeCode()
Run Code Online (Sandbox Code Playgroud)

然后我可以把我的代码放在compileTimeCodeproc中.

这可行,但似乎凌乱,过于复杂和不直观.它还需要更多的打字,并且很难干掉.

def*_*ef- 7

问题是什么?如果有更好的方法在编译时运行代码?

static:
  # Put code here
Run Code Online (Sandbox Code Playgroud)