Alex
Alex

Reputation: 4180

Use show() to print output

This question is a follow-up to this one I asked a couple of days ago. Following the suggestion from that post, I created a custom data type, and also overloaded the base.show() function. But the output is not what I expected. So I wonder if I misunderstood something.

type Output
    testname::String
    output::Float64
end


function show(io::IO,object::Output)
    println(io,"\tOutput Statistic for $(object.testname)")
    println(io,"$(object.output)")
end

I use the following function to illustrate

function MEDIAN(x::Array)
    Output("Median: ", median(x))
end

julia> x=randn(10)
julia> MEDIAN(x)
Output("Median: ",0.2267306855631679)

I want the output to be the following instead:

Median: 0.2267306855631679

Upvotes: 3

Views: 4702

Answers (1)

Keno Fischer
Keno Fischer

Reputation: 1405

To answer the question, you probably forgot to import Base.show

Upvotes: 4

Related Questions