在编译时运行Nim代码 [英] Run Nim code at compile time
本文介绍了在编译时运行Nim代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我知道,如果我定义一个 const
Nim会在编译时评估分配给它的任何内容,因此我可以执行以下操作:
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()
然后我可以将代码放入 compileTimeCode
过程。
and then I could put my code in the compileTimeCode
proc.
此方法有效,但看起来很杂乱,过于复杂且不直观。它还需要比实际输入更多的内容,并且很难 DRY 。
This works, but seems messy, overcomplicated and unintuitive. It also requires more typing than it should, and is difficult to DRY up.
推荐答案
有什么问题?如果在编译时有更好的方式运行代码?
What's the question? If there is a better way to run code at compile time?
static:
# Put code here
这篇关于在编译时运行Nim代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文