that works, thank you!
在 2015年11月6日星期五 UTC+8下午11:23:55,Matt Bauman写道:
>
> Whenever you define an IO method, you need to make sure that all IO
> methods you call within it also use that argument. Change println("x ...")
> to println(io, "x …").
>
> On Friday, November 6, 2015 at 8:17:56 AM UTC-5, Gnimuc Key wrote:
>>
>> we can define a good representation of a new type by overloading
>> `Base.show(io::IO, x::Foo)`:
>>
>> ```
>>
>> import Base: show
>>
>>
>> type Foo
>> x
>> y
>> end
>>
>> function show(io::IO, x::Foo)
>> println("x ---> $(x.x)")
>> println("y ---> $(x.y)")
>> end
>>
>> julia> Foo(1,2)
>> x ---> 1
>> y ---> 2
>>
>> ```
>>
>> but I don't know why julia will show `Foo` 3 times when running
>> `[Foo(1,2)]`:
>>
>> ```
>>
>> julia> [Foo(1,2)]
>> 1-element Array{Foo,1}:
>> x ---> 1
>> y ---> 2
>> x ---> 1
>> y ---> 2
>> x ---> 1
>> y ---> 2
>>
>> ```
>>
>> BTW, the whitespace in the beginning of 3rd line is so wired...
>>
>>
>