8
votes

If a package author has defined a custom show function for their composite type, is there a way to easily print the default show? That is, what Julia would have shown for the composite type before the customization?

I am using Juno to step through the code of complex functions to try and I want to see the data representation but the full structure of the struct isn't shown due to the custom printing.

2

2 Answers

8
votes

You can use Base.show_default.

For example, Measurements.jl defines custom printing of the Measurement type:

julia> using Measurements

julia> x = 3 ± 0.1
3.0 ± 0.1

julia> Base.show_default(stdout, x)
Measurement{Float64}(3.0, 0.1, 0x0000000000000003, Measurements.Derivatives((3.0, 0.1, 0x0000000000000003) => 1.0))
6
votes

You can use invoke to make sure the default show method is called:

julia> struct Bar
       a
       b
       c
       end

julia> Base.show(io::IO, b::Bar) = print(io, "Bar")

julia> Bar(1,2,3)
Bar

julia> invoke(show, Tuple{IO, Any}, stdout, Bar(1,2,3))
Bar(1, 2, 3)

Also note that dump can be very useful in that exact scenario:

julia> dump(Bar(1,2,3))
Bar
  a: Int64 1
  b: Int64 2
  c: Int64 3