Sunday, 4 January 2015

Julia (julialang): Installation and Hello World

I've decided to have a go at julia, a new language for mathematical computing that's been described to me as 'like MATLAB, but not crap'.

First thing is to get it installed. Since I'm using Debian Jessie, which is just in its pre-release freeze, I figure that the julia package that comes with it should work.

That package suggests that I also install its docs and ess, which is the emacs mode for R and allied languages, so I eventually type:

sudo apt-get install julia julia-doc ess

This pulls in a lot of dependencies (including R, but that's not a bad thing to have around if you're planning on doing a bit of machine learning)

Once it's finished churning, typing

julia

results in this rather pretty display:
               _
   _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation: http://docs.julialang.org
   _ _   _| |_  __ _   |  Type "help()" for help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.3.2
 _/ |\__'_|_|_|\__'_|  |  
|__/                   |  x86_64-linux-gnu


which is actually in colour on my terminal. Very modern!

And gives me a read-eval-print loop which works as expected.


julia> 2*3
6

julia> print("hello")
hello

Next I try creating a file hello.jl

# Hello Julia
print("hello\n")

Amazingly, emacs (with ess installed) highlights this correctly.

Both:

julia hello.jl

and

julia <hello.jl

seem to run it, I don't know which is preferred

which julia

tells me that the julia program is:

/usr/bin/julia

And if I add a shebang line to hello.jl

#!/usr/bin/julia

and make the file executable with

chmod +x hello.jl

then I can run it with:

./hello.jl

For a new language, that all went remarkably smoothly, and it seems to work in the usual unixy way.


No comments:

Post a Comment