JuliaIO / JLD.jl

Saving and loading julia variables while preserving native types
MIT License
277 stars 55 forks source link

Conditional loading requires file to exist at "Compile time" #195

Open krcools opened 6 years ago

krcools commented 6 years ago

I often use a pattern where my code can run in one of two modes:

This leads to code snippets like:

record = true
if record
    println("Recording mode...")
    a = 42
    @save "bench.jld" a
else
    println("Playback mode...")
    @load "bench.jld"
end

Running this leads to ErrorException("File bench.jld cannot be found") being thrown. Apparently the file is required to exist during macro expansion as opposed to at runtime.

Is this required in the current design of JLD or can this requirement be relaxed?

timholy commented 6 years ago

Give it a shot! But if memory serves those macros are pretty horrifying. Easiest is to use the functional forms of load and save.