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?
>

Reply via email to