First, the function you want is push!, not hcat: push! is the function to append a single element to an array, whereas hcat is for concatenating matrices horizontally (by columns).
Second, you can accomplish what you are trying much more simply with:
xvals = [real(e) for e in evals if abs(imag(e)) < 1e-6 && -1 <= real(e) <= 1]
Third, you are hitting the infamous global scope rule: when writing to a global variable A in a loop, you need to declare it as global A:
A = [0,]
for i in 1:10
global A = push!(A,i)
end
This is not needed in the REPL in Julia 1.5 (or in Jupyter in any version), and in scripts there is a clearer error message, so I’m guessing you are using a very old version of Julia? (If you are writing code inside functions rather than using globals in scripts, which is what you would do for most “serious” code, there is no need for any special declaration.)