What features does the `show` method have?

I’m looking at this project called ComputationalHomology.jl, and learning some Julia along the way. I notice that at line 122 of file constructions.jl there is this line:


splxs = map(Simplex, 1:n)

Which if I just (after using ComputationalHomology) run in the REPL (say with n = 10) spits out


"σ(1,)"
 "σ(2,)"
 "σ(3,)"
 "σ(4,)"
 "σ(5,)"
 "σ(6,)"
 "σ(7,)"
 "σ(8,)"
 "σ(9,)"
 "σ(10,)"

What cues me about this is the σ, and I went to look for where this comes from in the project. As far as I can tell, the relevant part of the code in the ComputationalHomology project is the following line 14 from simplex.jl (ie the “source file” for the above Simplex object):


show(io::IO, splx::Simplex) = show(io, "σ$(splx.vs)")

I’m wondering then if there is something I’m missing, or if the show function is what is default run when you run a function in the REPL.

Sorry if my syntax/jargon is not quite right, am quite new to this language, and looking to become more familiar!

2 Likes

Well, it’s two step process:

  1. You run a function which returns object
  2. This object is being shown in REPL with the help of the show method.

I.e. function itself doesn’t use show to display anything.

Maybe this talk will be of interest to you: JuliaCon 2020 | Display, show and print -- how Julia's display system works | Fredrik Ekre - YouTube

4 Likes

Ahhh, I see, thank you! The talk was helpful too :slight_smile:

3 Likes