I know I should open an issue, but I wanted to make you guys laugh too. Okay, I wanted to check file existence at compile time. Let's read the docs:

proc existsFile(filename: string): bool {..}

Returns true if the file exists, false otherwise.

No problem. I tried

from os import existsFile
const ex = existsFile("/tmp/a.txt")
echo "Okay"

I got

lib/nim/pure/os.nim(83, 12) Error: cannot 'importc' variable at compile time

Okay. Happy developing.

  • I tried to fuck with staticRead - at least it works at compile time
  • I wanted to compile a subprogram (aka "ls" on unix) which will tell me whether file exists, and call it by staticExec.
  • I googled.

Two days later. Found this post by Araq

News.txt (on bigbreak) contains this:

The following procs are now available at compile-time:

math.sqrt, math.ln, math.log10, math.log2, math.exp, math.round, math.arccos, math.arcsin, math.arctan, math.arctan2, math.cos, math.cosh, math.hypot, math.sinh, math.sin, math.tan, math.tanh, math.pow, math.trunc, math.floor, math.ceil, math.fmod, os.getEnv, os.existsEnv, os.dirExists, os.fileExists, system.writeFile

Wait, what? fileExists?!

... yep.

from os import fileExists
const ex = fileExists("/tmp/a.txt")
echo "Okay"


I guess you're interested what's the difference:

proc fileExists(filename: string): bool {..}

Synonym for existsFile

So when you want something to be done at compile time (and it doesn't work) - just try to reorder the words.

Happy nimming!

2018-03-12 20:28:58
lol wtf. Why have this synonym, I thought one of them was deprecated and was about to say "This is why all deprecated procs need to be removed before v1.0 is released"...
2018-03-12 20:55:14