What show function is called in the REPL?


#1

I assumed it was just show but at least for arrays something else is going on:

julia> rand(3,3)
3×3 Array{Float64,2}:
 0.945084   0.86556   0.727404
 0.128891   0.180756  0.228008
 0.0498265  0.639407  0.20455 

julia> sprint(show,rand(3,3))
"[0.397804 0.757501 0.348905; 0.113848 0.0424663 0.326405; 0.368243 0.606226 0.0291582]"

#2
julia> show(STDOUT, MIME"text/plain"(), rand(3,3))
3×3 Array{Float64,2}:
 0.753873  0.651132  0.0710547
 0.475354  0.970687  0.108144 
 0.813717  0.775238  0.681004 

#3

See also the Custom Pretty-printing section of the manual.


#4

Thanks, perfect.


#5

Actually it’s not quite that, rand(100,100) in the repl prints only parts of the values with some … in between, while sprint(Base.show,MIME"text/plain"(), rand(100,100)) prints the whole thing, which gets very slow for large matrices.


#6

Ho, I need to use an IOContext:

    io = IOBuffer()
    io = IOContext(io,:display_size=>(20,20))
    io = IOContext(io,:limit=>true)
    show(io,MIME"text/plain"(),rand(100,100))
    takebuf_string(io.io)

#7

You can also use display, in my REPL this looks like:

julia> show(rand(2,2))
[0.305285 0.479731; 0.260545 0.235768]
julia> display(rand(2,2))
2×2 Array{Float64,2}:
 0.952205  0.839303
 0.144267  0.90555