Experimental Julia magics in IPython

In [1]:
%load_ext juliamagic
In [2]:
%julia 1+2+3
Out[2]:
6
In [3]:
%julia 1+2+3.0
Out[3]:
6.0
In [4]:
%%julia

sum([1 2;3 4]^2)
Out[4]:
54
In [5]:
%%julia

sum([1 2;3 4.0]^2)
Out[5]:
54.0

For some reason, multiline blocks aren't executing quite right, so for now I'm putting them line by line. Need to investigate further. But even function definitions work:

In [6]:
%julia  fib(n) = n < 2 ? n : fib(n-1) + fib(n-2)
%julia fib(10)
Out[6]:
55

And once defined, they can be used as the state of the Julia interpreter is persistent:

In [7]:
%%julia
fib(20)
Out[7]:
6765
In []: