Is there a way to use a static calculated string value as the argument of an import statement?
For example:
import LIB&"tools"
where LIB was a defined symbol from the nim compile command - perhaps:
nim c -d:LIB=vector myproject.nim
so that myproject.nim would import vectortools.nim
Trying the above form of the import did not work.
import macros
const apple {.strdefine.} = "default_value"
macro toImport(x: static[string]): untyped = quote do: import `x`
toImport(apple & "tools")
nim c -d:apple=new_value myproject
shorter version
const apple {.strdefine.} = "default_value"
template toImport(x: static[string]): untyped = import x
toImport(apple & "tools")
Very cool. The toImport allows any static string expression to be used as the argument of the import.
I had seen the strdefine pragma but did not understand its purpose.
THANKS