Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define how type appears on the Julia REPL

I am not clear on how I should define the appearance of a type on the Julia REPL. There are a number of similar sounding functions, including: display, show, print, writemime etc.

like image 829
conjectures Avatar asked Feb 09 '23 15:02

conjectures


1 Answers

You need to overload Base.show() for the type.

julia> import Base: show

julia> type Foo
           x
           y
           z
       end

julia> Base.show(io::IO, f::Foo) = println(io, "Foo: x=$(f.x), y=$(f.y), z=$(f.z)")
show (generic function with 98 methods)

julia> Foo("Hello ", "World", "!")
Foo: x=Hello, y=World, z=!
like image 69
Chisholm Avatar answered Feb 18 '23 13:02

Chisholm