PureNerdism, The Daily Duffy

The Daily Pig: Julia Code

 
 

Mister Pig. Brought to you daily. Almost.

Here I am playing with some Julia code. My favorite Julia. Don’t tell Sarah. Sarah source code needs a complete overhaul.

Interesting aspects of Julia, parenthesis are for functions, square brackets are for indexing. This is a biggie when translating from other languages. The human, not the machine, has to decide
is this a function with two arguments or a matrix with two indices, or a vector with one argument.

 

julia> a[1,1]
0.13688570174785997

Vector with 5 elements
julia> [i for i=1:5]
5-element Int64 Array
1
2
3
4
5

julia. [trace(rand(n,n) for n=1.5]
5-element Float64 Array:
0.0493803
0.655186
2.14788
1.40687
3.12393

julia> x = rand(10); [ x[i] + x[i+1] for i=1:9]
9-element Any Array:
1.19657
1.14956
1.01969
0.331159
0.365137
0.571998
0.974055
1.30639
0.929632