I’m trying to define short-form and long-form printing for a custom type. It seems to work as expected except when I put objects of the custom type in a vector. Here’s the code:
struct Foo
x::Int
y::Int
end
function Base.show(io::IO, ::MIME"text/plain", f::Foo)
print(io, "Foo: {", f.x, ", ", f.y, "}")
end
function Base.show(io::IO, f::Foo)
print(io, "{", f.x, ", ", f.y, "}")
end
Long-form printing works:
julia> Foo(1, 2)
Foo: {1, 2}
And short-form printing works in a tuple or pair:
julia> (Foo(1, 2), Foo(3, 4))
({1, 2}, {3, 4})
julia> Foo(1, 2) => Foo(3, 4)
{1, 2} => {3, 4}
But short-form printing is not working in a vector:
julia> [Foo(1, 2), Foo(3, 4)]
2-element Vector{Foo}:
Foo: {1, 2}
Foo: {3, 4}
Does anyone know what is going on here? I thought that vector printing is supposed to use the short-form, as the example in the manual shows.
(Code tested on v1.8.2)
julia> VERSION
v"1.8.2"