Okay. I also missed your point about not wanting to depend on external packages.
Cheers! Kevin On Mon, Sep 1, 2014 at 12:56 AM, Robert Feldt <robert.fe...@gmail.com> wrote: > Thanks Kevin, > > I agree that HDF5 or even json are better choices in general but for short > scripts with small state they might be overkill imho. > > Cheers, Robert > > söndag 31 augusti 2014 skrev Kevin Squire <kevin.squ...@gmail.com>: > > Hi Robert, >> >> You and the OP will have to check whether this addresses you use case, >> but did you see this recent message: >> https://groups.google.com/forum/m/#!topic/julia-users/yHXjH7b7r1o >> >> Cheers, >> Kevin >> >> On Sunday, August 31, 2014, Robert Feldt <robert.fe...@gmail.com> wrote: >> >>> This is an old thread but I needed something similar to the original >>> poster and didn't want to depend on external packages. >>> >>> A quick and dirty solution can be to save to file with showall and then >>> eval and parse back in. This works for the built-in data types and for >>> small data but I'm sure there are many disadvantages... Anyway, I've found >>> it useful in small scripts that need to save some state between runs. Code >>> and example below. >>> >>> Regards, >>> >>> /Robert Feldt >>> >>> macro savevars(filename, vars...) >>> printexprs = map(vars) do var >>> :(print(f, ";", $(string(var)), " = "); showall(f, $(esc(var)))) >>> end >>> quote >>> local f = open($(esc(filename)), "w") >>> try >>> $(Expr(:block, printexprs...)) >>> finally >>> close(f) >>> end >>> end >>> end >>> >>> a = 1 >>> b = 2.345 >>> c = [1,2,3] >>> d = {:a => "a", :b => 1, "c" => "arne", "d1" => {1 => 2}} >>> @savevars("t", a, b, c, d) >>> >>> function loadvars(filename) >>> f = open(filename, "r") >>> try >>> eval(parse(readall(f))) >>> finally >>> close(f) >>> end >>> end >>> >>> a = b = c = d = -1 >>> loadvars("t") >>> >>> julia> a >>> 1 >>> >>> julia> b >>> 2.345 >>> >>> julia> c >>> 3-element Array{Int64,1}: >>> 1 >>> 2 >>> 3 >>> >>> julia> d >>> Dict{Any,Any} with 4 entries: >>> :b => 1 >>> "c" => "arne" >>> "d1" => {1=>2} >>> :a => "a" >>> >>> Den tisdagen den 1:e april 2014 kl. 14:41:53 UTC+2 skrev Freddy Chua: >>>> >>>> in matlab, there's save and load >>>> >>>> in java, there's object serialization >>>> >>>> So does julia have this feature? >>>> >>> > > -- > Best regards, > > /Robert Feldt > -- > Tech. Dr. (PhD), Professor of Software Engineering > Blekinge Institute of Technology, Software Engineering Research Lab, and > Chalmers, Software Engineering Dept > Explanea.com - Igniting your Software innovation > robert.feldt (a) bth.se or robert.feldt (a) chalmers.se or > robert.feldt (a) gmail.com > Mobile phone: +46 (0) 733 580 580 > http://www.robertfeldt.net <http://www.cse.chalmers.se/~feldt> > >