Run Nim code at compile time

点点圈 提交于 2019-12-10 17:08:46

问题


So I know that if I define a const Nim will evaluate whatever I assign to it at compile time, so I could do something like this:

proc compileTimeCode: bool =
  # Put code here
  return true

const _ = compileTimeCode()

and then I could put my code in the compileTimeCode proc.

This works, but seems messy, overcomplicated and unintuitive. It also requires more typing than it should, and is difficult to DRY up.


回答1:


What's the question? If there is a better way to run code at compile time?

static:
  # Put code here


来源:https://stackoverflow.com/questions/34711495/run-nim-code-at-compile-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!