Julia
- Day 1
- julia> typeof(5)
- ~0 位取反
- 5 $ 6 //=> 3
- implicit = {:a => 1, :b => 2, :c => 3}
- explicit = [:a => 1, :b => 2, :c => 3] //静态类型限定?
- Float64[1, 2, 3] //有点Go语言语法的味道?
- 切片:animals[2:end]
- 多维数组:A = [1 2 3; 4 5 6; 7 8 9] //Matlab?
- v .* [0.5; 1.2; 0.1] //点乘
- v' * v //内积
- Day 2
- for a = [1, 2, 3] println("$a") end //这个字符串求值借用的Perl语法?
- abstract Story
- type Book <: Story ... end //没有指定成员的类型?
- super(Book)
- subtypes(Story)
- numbers = 1:10
- +(numbers...)
- In Julia, each version of a function is called a method, 但‘不属于特定的类型’?==> Multiple dispatch
- 并发:
- addprocs(2)
- r1 = remotecall(2, rand, 10000000) //嗯?可以直接发起远程调用?
- rand_list = fetch(r1) //阻塞等待结果返回(感觉这里的语法有点太原始的,不过适合于数值计算的使用场景)
- @parallel (+) for i = 1:times ... end //循环并行化?
- Interview with Julia’s Founders: Jeff Bezanson, Stefan Karpinski, Viral Shah, Alan Edelman
- Julia注重性能(CPU计算速度、内存布局)?
- Day 3
- e = :(println("Hello!"))
- typeof(e) //=> Expr
- (e.head, e.args) //=> (:call,{:println,"Hello!"}) 又是Lisp风格的代码结构表示?
- macro unless(t, b) quote ... end end //注意,Julia代码不需要写‘return’
- julia> Pkg.add("Images") //靠,在线的包管理,这个牛
- 感觉Julia可以直接当作命令行的Matlab来用了?正如R语言对于S
- http://media.pragprog.com/titles/7lang/code/julia/Codec.jl (代码略)
- julia> using Codec
- julia> freqs = Codec.blockdct6(img)
- img2 = Codec.blockidct(freqs)
- Weaknesses
- The first is its youth, and the second is the lack of available packages(这个,-_-)
- As Graydon Hoare, creator of the Rust language, puts it, Julia is a “Goldilocks language.” It’s just right.