So just to start, I am very new to nim I started reading about it and programming in it 4 days ago. I understand that using static like this
static:
var some_variable = 10
evaluates the statement at compile time and uses the Nim VM to do that
my questions are, is there a way to use these static variables outside of the module they are defined in, and does anyone know where static is defined so i can look at how it is coded so that if my first question results in no I can possibly recreate a version of static that could
is there a way to use these static variables outside of the module they are defined in
Sure, just give them an export marker. (The asterisk.)
Here I have made an example of what is happening
#module A
static:
var test=0
proc test_proc(): void {.discardable,compileTime.} =
var a = test
echo a
#module B
import A
static:
test_proc()
this will give me an "Error: cannot evaluate at compile time: test" for line 6 of module A
Looks like you need a compileTime var:
var test {.compileTime.} = 0
Bizarre enough, the following seems to work:
#module A
static:
var test=0
proc test_proc(): void {.discardable,compileTime.} =
var a = test
echo a
static:
test_proc()
#module B
import A
static:
test_proc()
:-o