은 print()
및 show
정의 (및 show
는 print
에 따라 다름) 당신에 의존하려는 경우
function print(io::IO, v::VersionNumber)
print(io, v.major)
print(io, '.')
print(io, v.minor)
print(io, '.')
print(io, v.patch)
if !isempty(v.prerelease)
print(io, '-')
print_joined(io, v.prerelease,'.')
end
if !isempty(v.build)
print(io, '+')
print_joined(io, v.build,'.')
end
end
show(io, v::VersionNumber) = print(io, "v\"", v, "\"")
그것은 당신에게 달려있다이 시점에서 보이는 자료 소스가 신뢰할 수있는 모든 참조 일 경우 base/version.jl
가있다 하나의 공통 기능; 그런 식으로 모든 기능을 구현하면됩니다. 예 :
type Foo
end
import Base.string
function string(x::Foo)
return "a Foo()"
end
import Base.print
print(io::IO, x::Foo) = print(io, string(x))
import Base.show
show(io::IO, x::Foo) = print(io, "This is ", x)
-
julia> f = Foo()
This is a Foo()