Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run Nim code at compile time

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.

like image 216
squirl Avatar asked Jan 10 '16 22:01

squirl


People also ask

How do I run a Nim code?

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.

Is Nim compiled?

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula.

How Fast Is Nim language?

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.

Does Nim compile to C?

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 .


1 Answers

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

static:
  # Put code here

Reference

like image 112
def- Avatar answered Sep 19 '22 11:09

def-