Q:

How to change the name of a variable in a for loop

I would like to change the name of a variable within a for loop, using the loop index in the name of the variable. 
I've tried the following syntax:
A= [1,2,3]
for i = 1:3
    global x{i}
    x{i}=A[i]
end

This isn't the right syntax, and googling has not led me to the correct syntax. 
I've also tried 
A= [1,2,3]
for i = 1:3
    global x$i
    x$i=A[i]
end

My hope is to create three variables, x1, x2, and x3 each containing the appropriate element of A. Maybe I don't even need to write a loop to do this--I'm open to completely different methods of accomplishing this as well.

A:

As others have said, it's a bit questionable whether one should do this, but if this is really what you want to do, here's how you can do it:
A = [1, 2, 3]
for i = 1:3
    @eval $(Symbol("x$i")) = $(A[i])
end

after which these global variables are assigned:
julia> x1, x2, x3
(1, 2, 3)

The inner expression is equivalent to writing this:
eval(:($(Symbol("x$i")) = $(A[i])))

In other words, you construct and then eval an assignment expression where the left hand side is the symbol x$i and the right hand side is the value of A[i].
Note that you can only define global variables like this, not local ones because eval always operates in global scope. Other languages have "local eval", Julia does not because the very possibility of local eval in a language makes optimization much harder.

