Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Which unique show to use for nested and non-nested structures? #20059

Closed
dpsanders opened this issue Jan 16, 2017 · 2 comments
Closed

Which unique show to use for nested and non-nested structures? #20059

dpsanders opened this issue Jan 16, 2017 · 2 comments
Labels
display and printing Aesthetics and correctness of printed representations of objects.

Comments

@dpsanders
Copy link
Contributor

In the following example, we see that defining the 3-argument form of show is required to change the output of a type, but the 2-argument form must also be explicitly defined to get the desired behaviour inside another data structure (e.g. an array). cc @shashi

julia> using StaticArrays

julia> Base.show{N,T}(io::IO, ::MIME"text/plain", vec::SVector{N,T}) = print(io, "Hello")
show (generic function with 203 methods)

julia> SVector(1,2)
Hello

julia> [SVector(1,2,3)]
1-element Array{StaticArrays.SVector{3,Int64},1}:
 [1,2,3]

julia> Base.show{N,T}(io::IO, vec::SVector{N,T}) = print(io, "Hello")
show (generic function with 204 methods)

julia> [SVector(1,2,3)]
1-element Array{StaticArrays.SVector{3,Int64},1}:
 Hello

Also,

julia> immutable X x end

julia> X(SVector(2,2))
X(Hello)
@ararslan ararslan added the display and printing Aesthetics and correctness of printed representations of objects. label Jan 16, 2017
@shashi
Copy link
Contributor

shashi commented Jan 30, 2017

For another ugly situation created by show(IOContext, x) methods see: JuliaLang/IJulia.jl#509

@laborg
Copy link
Contributor

laborg commented Feb 10, 2022

This works now. (See clarification for container types in #36076)

julia> using StaticArrays

julia> Base.show(io::IO, ::MIME"text/plain", vec::SVector{N,T}) where{N,T}  = print(io, "Hello")

julia> SVector(1,2)
Hello

julia> [SVector(1,2,3)]
1-element Vector{SVector{3, Int64}}:
 Hello

@vtjnash vtjnash closed this as completed Feb 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
display and printing Aesthetics and correctness of printed representations of objects.
Projects
None yet
Development

No branches or pull requests

5 participants