2015-11-04 21 views
0

說我進入:在julia REPL上調用哪些函數來顯示(數組)變量?

julia> X = randn(3,4) 
3x4 Array{Float64,2}: 
-0.862092 0.78568  0.140078 -0.0409951 
-0.157692 0.0838577 1.38264 -0.296809 
    1.40242 -0.628556 -0.500275 0.258898 

被稱爲什麼函數生成的輸出中?

請注意,重載Base.show似乎不足以改變此行爲,因此我不確定要去哪裏。

julia> Base.show(io::IO, A::Array{Float64, 2}) = println("Humbug") 
show (generic function with 120 methods) 

julia> X 
3x4 Array{Float64,2}: 
-0.862092 0.78568  0.140078 -0.0409951 
-0.157692 0.0838577 1.38264 -0.296809 
    1.40242 -0.628556 -0.500275 0.258898 

是不是也許,我將不得不改變基地/ array.jl源代碼,這樣的改變會工作之前重建朱莉婭的情況?請注意,這和用戶定義類型之間的區別:

julia> type foo 
     x::Float32 
     s::ASCIIString 
     end 

julia> ob = foo(1., "boo") 
foo(1.0f0,"boo") 

julia> Base.show(io::IO, someob::foo) = print("Humbug!") 
show (generic function with 123 methods) 

julia> ob 
Humbug! 
+0

'Base.show(X)'會給你'Humbug'。 :) – Gnimuc

回答

4

好,你應該重載display()

julia> Base.display(A::Array{Float64, 2}) = println("Humbug") 
display (generic function with 11 methods) 

julia> X 
Humbug 

你能找到的定義REPL.jl