LoginSignup
1
0

More than 5 years have passed since last update.

Juliaで自作のCompositeTypeとprint/println

Posted at

自分でtypeしたComposite Typeのprint/printlnについて、以下のような実装をしている。参考にした情報はだいぶ古い。一応Julia v0.5.0(2016-09-19-18:14 UTC)とv0.6.0(2017-06-19 13:05 UTC)で動いた。何を実装するのが一番いい感じのやり方なのか知りたい。

# 宣言
type MyInterval
  s::Int64
  e::Int64
end

function Base.show(io::IO, itv::MyInterval)
  print(io, "[$(itv.s),$(itv.e)]")
end

# 実行
julia> itv = MyInterval(1, 10)
[1, 10]

julia> println(itv)
[1, 10]
1
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0