how can I customize the (REPL) display of built-in types? I tried:
julia> Base.show(x::Int)= if (x<10) print(x) else print("large"); end;#if#
julia> show(12)
large
julia> 12 ## what is actually invoked here?
12
This is of course a terrible example. A more useful example would switch to scientific notation for my choice of small values. Unfortunately, a couple of my attempts here segfaulted Julia:
julia> using Printf;
julia> import Base.show
julia> show(io::IO, x::Float64)= if (x<0.01) print(io, @sprintf("%e", x)) else print(io,x); end
show (generic function with 296 methods)
julia> show( 0.0001 )
1.000000e-04
julia> show( 0.01 )
Segmentation fault: 11
julia> Base.show(io::IO,x::Int)= if (x<10); print(io,"small"); else; print(io,"large"); end
mallC>
mallC21
large
mallC1
small
In your example print(x) calls your newly defined show method and that predictable creates a stack overflow. Overloading that particular method seems to mess up the Julia REPL a bit though…