# What show function is called in the REPL?

**URL:** <https://discourse.julialang.org/t/what-show-function-is-called-in-the-repl/3262>\
**Category:** General Usage\
**Created:** [April 18, 2017, 7:42am UTC](https://discourse.julialang.org/t/what-show-function-is-called-in-the-repl/3262 "2017-04-18T07:42:44Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonathanBieler](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@jonathanBieler](https://discourse.julialang.org/u/jonathanBieler)\
**Post date:** [April 18, 2017, 7:42am UTC](https://discourse.julialang.org/t/what-show-function-is-called-in-the-repl/3262/1 "2017-04-18T07:42:44Z")

</div>

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

```julia
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]"

```

---

<div class="post-metadata">

**Author:** ![Evizero](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/evizero/32/10118_2.png) [@Evizero](https://discourse.julialang.org/u/Evizero)\
**Post date:** [April 18, 2017, 9:20am UTC](https://discourse.julialang.org/t/what-show-function-is-called-in-the-repl/3262/2 "2017-04-18T09:20:02Z")

</div>

```julia
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 

```

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [April 18, 2017, 12:08pm UTC](https://discourse.julialang.org/t/what-show-function-is-called-in-the-repl/3262/3 "2017-04-18T12:08:48Z")

</div>

See also the [_Custom Pretty-printing_ section of the manual](https://docs.julialang.org/en/latest/manual/types.html#Custom-pretty-printing-1).

---

<div class="post-metadata">

**Author:** ![jonathanBieler](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@jonathanBieler](https://discourse.julialang.org/u/jonathanBieler)\
**Post date:** [April 18, 2017, 12:32pm UTC](https://discourse.julialang.org/t/what-show-function-is-called-in-the-repl/3262/4 "2017-04-18T12:32:44Z")

</div>

Thanks, perfect.

---

<div class="post-metadata">

**Author:** ![jonathanBieler](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@jonathanBieler](https://discourse.julialang.org/u/jonathanBieler)\
**Post date:** [June 27, 2017, 3:38pm UTC](https://discourse.julialang.org/t/what-show-function-is-called-in-the-repl/3262/5 "2017-06-27T15:38:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jonathanBieler](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@jonathanBieler](https://discourse.julialang.org/u/jonathanBieler)\
**Post date:** [June 27, 2017, 4:01pm UTC](https://discourse.julialang.org/t/what-show-function-is-called-in-the-repl/3262/6 "2017-06-27T16:01:37Z")

</div>

Ho, I need to use an `IOContext`:

```julia
    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)

```

---

<div class="post-metadata">

**Author:** ![kslimes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kslimes/32/44413_2.png) [@kslimes](https://discourse.julialang.org/u/kslimes)\
**Post date:** [June 27, 2017, 6:07pm UTC](https://discourse.julialang.org/t/what-show-function-is-called-in-the-repl/3262/7 "2017-06-27T18:07:48Z")

</div>

You can also use [`display`](https://docs.julialang.org/en/latest/stdlib/io-network/#Base.Multimedia.display), in my REPL this looks like:

```julia
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

```

---

<div class="post-metadata">

**Author:** ![NHDaly](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nhdaly/32/1413_2.png) [@NHDaly](https://discourse.julialang.org/u/NHDaly)\
**Post date:** [June 12, 2019, 6:15pm UTC](https://discourse.julialang.org/t/what-show-function-is-called-in-the-repl/3262/8 "2019-06-12T18:15:57Z")

</div>

Sorry to revive an old thread, but I have one more question about this.

The docs agree with everything said above, that technically the REPL calls `display()`, but you can also use `show(stdout, MIME("text/plain"), z)` to achieve the same thing:

> Technically, the REPL calls `display(z)` to display the result of executing a line, which defaults to `show(stdout, MIME("text/plain"), z)` , which in turn defaults to `show(stdout, z)` , but you should _not_ define new [`display`](https://docs.julialang.org/en/v1.1/base/io-network/#Base.Multimedia.display) methods unless you are defining a new multimedia display handler (see [Multimedia I/O](https://docs.julialang.org/en/v1.1/base/io-network/#Multimedia-I/O-1)).

But I was a little surprised by the difference in how `nothing` is handled. Both of those methods above, print `nothing` for `display(nothing)`, where the REPL just doesn’t print anything:

```julia
julia> display(nothing)
nothing

julia> show(stdout, MIME("text/plain"), nothing)
nothing
julia> nothing

julia>

```

Is there a bit more magic where the REPL actually has an if-statement that only calls `display()` if the result is not a `Nothing`?

EDIT: Ah, yes, here it is. I managed to find it after a bit more digging; I’m pretty sure this is exactly that if-statement:

> <https://github.com/JuliaLang/julia/blob/master/stdlib/REPL/src/REPL.jl#L153>

---

<div class="post-metadata">

**Author:** ![jonathanBieler](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@jonathanBieler](https://discourse.julialang.org/u/jonathanBieler)\
**Post date:** [June 12, 2019, 7:25pm UTC](https://discourse.julialang.org/t/what-show-function-is-called-in-the-repl/3262/9 "2019-06-12T19:25:01Z")

</div>

This is a bit awkward since nothing is now part of the API of important functions, e.g.:

```julia
    julia> findfirst([false])
    

```
