Reputation: 21
Is it possible to evalute a string to an expression containing a string ? To give a mwe :
eval(Meta.parse("x = 2"))
is evaluted to:
x = 2
But I would like x to be a string itself. My naive try in making x a string:
eval(Meta.parse("x = "2" "))
which i would like to be evaluted to
x = "2"
gives me an error. Therefore, my question is: Is it possible to do this, using only strings ?
Upvotes: 2
Views: 143
Reputation: 42264
@August has answered the question, however just one another way usually more practical when doing metaprogramming:
julia> eval(:(x= "2"));
julia> x
"2"
This nicely works with interpolation:
julia> z="hello";
julia> eval(:(x2 = $z));
julia> x2
"hello"
Upvotes: 2