Why am I getting five vectors instead of one?

arr = []
[push!(arr,Char(ch)) for ch in "flarp"]

5-element Vector{Vector{Any}}:
[‘f’, ‘l’, ‘a’, ‘r’, ‘p’]
[‘f’, ‘l’, ‘a’, ‘r’, ‘p’]
[‘f’, ‘l’, ‘a’, ‘r’, ‘p’]
[‘f’, ‘l’, ‘a’, ‘r’, ‘p’]
[‘f’, ‘l’, ‘a’, ‘r’, ‘p’]

Please, quote your code with triple backquotes: Discourse is doing lots of automagic rendering, it took me a while to figure out was an empty vector [].

The fact is that push! returns the collection you’re pushing to, so each element of the comprehension is arr, so the final result is

[arr, arr, arr, arr, arr]

with arr being

Any['f', 'l', 'a', 'r', 'p']

Also, note that you are getting a vector at the end, but it’s a vector of vectors

3 Likes