2021/01/23 NGK2021S
antimon2(後藤 俊介)
そろそろみんな Julia の有能さに気付いても良いころ
- Rのように中身がぐちゃぐちゃでなく、
- Rubyのように遅くなく、
- Lispのように原始的またはエレファントでなく、
- Prologのように変態的なところはなく、
- Javaのように硬すぎることはなく、
- Haskellのように抽象的すぎない
ほどよい言語である
- C のように高速だけど、
Ruby のような動的型付言語である- Lisp のようにプログラムと同等に扱えるマクロがあって、しかも
Matlab のような直感的な数式表現もできる- Python のように総合的なプログラミングができて、
R のように統計処理も得意で、
Perl のように文字列処理もできて、
Matlab のように線形代数もできて、
shell のように複数のプログラムを組み合わせることもできる- 超初心者にも習得は簡単で、
超上級者の満足にも応えられる- インタラクティブにも動作して、コンパイルもできる
(Why We Created Julia から抜粋・私訳)
をいつもなら紹介するのですが…
digraph TypeTree {
nodesep=1.0
node [fontname=Courier,shape=box,style=filled, fillcolor=gray95]
edge [arrowsize=0.8]
edge [arrowtail="empty" dir=back]
Any -> AbstractString
Any -> Number
Any -> _others
_others [label="...",shape=none,style=none,fillcolor=transparent]
AbstractString -> SomeStringSubtypes
AbstractString -> String
SomeStringSubtypes [label="...",shape=none,style=none,fillcolor=transparent]
Number -> Complex
Number -> Real
Real -> AbstractFloat
Real -> AbstractIrrational
Real -> Integer
Real -> Rational
AbstractFloat -> x1
x1 [label="...",shape=none,style=none,fillcolor=transparent]
AbstractFloat -> Float64
Integer -> Bool
Bool [label="...",shape=none,style=none,fillcolor=transparent]
Integer -> Signed
Signed -> Int
AbstractIrrational -> x2
x2 [label="...",shape=none,style=none,fillcolor=transparent]
Integer -> Unsigned
Unsigned -> x4
x4 [label="...",shape=none,style=none,fillcolor=transparent]
Signed -> x5
x5 [label="...",shape=none,style=none,fillcolor=transparent]
}
abstract type Point{T<:Real} end
struct Point2D{T} <: Point{T}
x::T
y::T
end
mutable struct MPoint2D{T} <: Point{T}
x::T
y::T
end
julia> double(x::Number) = 2x
double (generic function with 1 method)
julia> double(x::AbstractString) = x^2
double (generic function with 2 methods)
julia> double(π)
6.283185307179586
julia> double("😄")
"😄😄"
julia> @code_typed double(1)
CodeInfo(
1 ─ %1 = Base.mul_int(2, x)::Int64
└── return %1
) => Int64
julia> @code_typed double(9.9)
CodeInfo(
1 ─ %1 = Base.sitofp(Float64, 2)::Float64
│ %2 = Base.mul_float(%1, x)::Float64
└── return %2
) => Float64
julia> @code_typed double(π)
CodeInfo(
1 ─ return 6.283185307179586
) => Float64
そろそろみんな Julia のことを
もっと知りたくなってきましたよね?
ご清聴ありがとうございます。