[julia-users] How do I turn a string into a variable
I want to be able to write: @makevar("life", 42) which will expand to life = 42 How do I do this? Why do I want to do it? Because it would be cool to have a feature like in Octave where I could load an HDF5 file, and it automatically sets the variables from the file.
Re: [julia-users] How do I turn a string into a variable
It's easy to write a macro that takes a static literal string and makes a variable out of it. It's much harder (maybe impossible) to write a macro that takes in a variable that happens to be bound to a string value and to make a variable out of the value you happen to have stored in that variable. Another way to put it: macros don't exist inside of the world of values -- they only live in the world of syntax. Could you get a similar (and cleaner) effect by populating a Dict instead? -- John On Dec 17, 2014, at 5:37 AM, Zeta Convex wrote: > I want to be able to write: > @makevar("life", 42) > which will expand to >life = 42 > How do I do this? > > Why do I want to do it? Because it would be cool to have a feature like in > Octave where I could load an HDF5 file, and it automatically sets the > variables from the file.
Re: [julia-users] How do I turn a string into a variable
For the usage goal, have you seen HDF5.jl? https://github.com/timholy/HDF5.jl#quickstart The @save and @load macros will do this for you (there are some limitations - but Tim, Simon, et al. have pushed things about as far as they possibly can at present). On Wed, Dec 17, 2014 at 5:37 AM, Zeta Convex wrote: > > I want to be able to write: > @makevar("life", 42) > which will expand to >life = 42 > How do I do this? > > Why do I want to do it? Because it would be cool to have a feature like in > Octave where I could load an HDF5 file, and it automatically sets the > variables from the file. >
Re: [julia-users] How do I turn a string into a variable
On Wednesday, 17 December 2014 14:29:27 UTC, Isaiah wrote: > > For the usage goal, have you seen HDF5.jl? > > https://github.com/timholy/HDF5.jl#quickstart > > The @save and @load macros will do this for you > Cool beans.