Save variable to variable name

Giving up…
I have a bunch of JulaiDB tables and I want to save them. To avoid zipping through a list of their variables and an irritatingly similar list of the variables’ names, I’d like to solve this with metaprogramming.

So instead of this:

for (variable, name) in zip((table1, table2, table3), ("table1", "table2", "table3"))
    save(variable, joinpath(repo, "$name.jldb"))

it would look something like this (but this doesn’t work):

for s in (:table1, :table2, :table3)
    @eval save($s, joinpath(repo, "$s.jldb"))

This should work:

@eval save($s, joinpath(repo, $("$s.jldb")))

You need to rounds of $: one for interpolating the symbol into the expression; another to interpolate the symbol name into the string (exactly like you’d have to without metaprogramming)

1 Like