Julia

Started by TomToad, October 28, 2019, 21:39:18

Previous topic - Next topic

TomToad

While looking through different programming languages, I came across one called Julia. https://julialang.org/
It can be run from an interpreter like Python, or compiled to native code.  It also will interface with C/C++, so you can use libraries from there.  It is mainly for science and math programs (i.e. statistical analisys, machine learning, etc...).  It has a nice set of features that I haven't seen anywhere else.

You can write more mathlike code, such as 2x+1 instead of 2*x+1.  Use pi or π. sqrt(num) or √num, etc.  You can use any unicode character for variable namesm as long as it doesn't start with a number or reserved character, so if you would rather use tau instead of 2*pi, you can assign it by typing τ=2π then you can use τ*radius instead of 2π*radius.

Julia seems to give you multiple ways of doing things.  Functions also are more powerful.  Supposing I want to find the distance between two poins.  I could write a function like this
Function Distance(p1,p2)
    sqrt(sum((p2-p1)^2))
end

or like this
Distance(p1,p2)=sqrt(sum((p2-p1).^2))
or like this
Distance(p1,p2)=(p2-p1).^2|>sum|>sqrt
They all do the same thing.  Nice thing is that it will work regardless of the dimentions I am using
#two points on a line
p1 = 10
p2 = 15
println(Distance(p1,p2))

#two pints on a plane
p1 = [10,10]
p2 = [15,15]
println(Distance(p1,p2))

#two points in 3d space
p1 = [10,10,10]
p2 = [15,15,15]
println(Distance(p1,p2))


Still have a lot more to read up on.  :)
------------------------------------------------
8 rabbits equals 1 rabbyte.