Run Nim code at compile time
Asked Answered
M

1

8

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.

Mig answered 10/1, 2016 at 22:23 Comment(0)
S
10

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

static:
  # Put code here

Reference

Sudan answered 10/1, 2016 at 23:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.