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.
To see all compiler options, type nim --help in your terminal. If you're using VSCode with the Code Runner extension mentioned before, you'll just have to press Ctrl+Alt+N and your file will be compiled and run.
Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula.
Applications written in Nim are very fast; in many cases, just as fast as applications written in C, and more than thirteen times faster than applications written in Python. Efficiency is the highest priority, and some features make optimizing code easy.
The Nim compiler supports mainly two backend families: the C, C++ and Objective-C targets and the JavaScript target. The C like targets creates source files that can be compiled into a library or a final executable. The JavaScript target can generate a .
What's the question? If there is a better way to run code at compile time?
static:
# Put code here
Reference
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With