julia> x = ["do", "re", "mi", "fa"]
4-element Vector{String}:
"do"
"re"
"mi"
"fa"
julia> append!(x,"sol")
ERROR: MethodError: Cannot `convert` an object of type Char to an object of type String
And the reason why append! works in the first case is that numbers are iterable. As it happens so are strings, but they iterate over their characters, which causes the type mismatch in the second case.
I think what’s particularly confusing here is that single numbers are “iterable”, yielding a single element.
For example
x = 42
for i in x
println(i)
end
will print 42.
Looking at the method hit for append!(x, 5), we see
julia> methods(append!, Tuple{Vector{Int}, Int})
# 1 method for generic function "append!" from Base:
[1] append!(a::AbstractVector, iter)
@ array.jl:1187
Same if we checked for args of Tuple{Vector{String}, String}.
So when using append!, julia will try to iterate through the second argument, adding it’s elements to the first argument. The confusing part happens when iterating through a number yields a single number of the same type, while iterating though a string yields a sequence of Char, which is of a different type from the element type of the first argument.