Hello nim lovers! Another portion of dumb questions from nim newbie 

1) Consider this project structure: 
    
    
    app.nimble
    app/
       - version.txt  # contains "0.1.1-3"
       - utils.nim
    

utils.nim contains getVersion helper which just reads from file: 
    
    
    proc getVersion*(versionFile:string): seq[string] =
      staticRead(versionFile).split('-')  # static is required because I need 
this value at compile time
    

app.nimble: 
    
    
    const
      versionFile = "app/version.txt"
    # ...
    task version, "Get version":
      echo "Proc call: " & $(getVersion(versionFile))
      echo "Inline call: " & $(staticRead(versionFile).split('-'))
    

Now here is the magic: 
    
    
    > nimble version
      Executing task version in .../app.nimble
    Proc call: @[0.1]  <-- WTF?!
    Inline call: @[0.1.1, 3]
    

Okay, it looks like calling staticRead is cached somehow when using a proc 
(cause I had "0.1" some time ago). But why, and how to avoid it?

2) My versionFile must be defined **relative to `utils.nim` location** because 
that's where staticRead resides. If I move utils somewhere else, I would need 
to change versionFile's path which is absolutely terrible!

3) Also, just curious why we have to use staticRead at all? Looks like const 
already marks expressions as compile-time: 
    
    
    const
      constEval = contains("abc", 'b') # computed at compile time, no need to 
use staticContains or smth
      data = readFile("somefile")  # <-- OOPS! doesn't work at compile time
      data = staticRead("somefile")  # <-- will work
    

Cannot nim distinguish between compile/runtime and call appropriate read 
function accordingly?

Reply via email to