## 2015-08-08

### Julia (computer language)

Installed Julia, just to take a look at it. (A filler article follows…)

Julia is one of those rare computer languages that accept a more natural syntax for multiplication (2x instead of 2 * x), and it's the only language I know (so far) that understands (in boolean contexts) a < b < c the same way you would do — most of the languages require you split it into two conditions combined through a logical and.

It's only syntactic sugar, but I always wondered why few languages decided to give the user such a pleasure. In particular, the * is often unnecessary since there can't be any kind of ambiguity: a numeric token followed by a variable name token should imply a * between. Another language which understands 2x (or similar) is METAfont, altogether with its descendants/clones (among these, MetaPost).

So, in Julia the following lines give the expected, correct results:


x = 5
println(2x)         # -> 10
println(2(x+1))     # -> 12
println(2(3+1))     # -> 8
println(1 < x < 6)) # -> true


With respect to *, it's similar to Metafont.


x := 5;
show(2x);         # -> 10
show(2(x+1));     # -> 12
show(2(3+1));     # -> 8

Except that Metafont complains for things like 1 < x < 6, which end up to comparing a boolean with a “known numeric” (incompatible types for Metafont).

Julia has also a model produce and consume, which is helpful to play with coroutines — see also my mediocre exploration of the topic in Crumbs of coroutines, Particles of coroutines and Coroutines or goroutines?.

Syntax apart, it seems similar to Go's channels, except that the “channel” in Julia is bound to a single producer, while in Go a channel is more general (if I've understood correctly what I've seen quickly in Julia). In fact, examples from the docs are:


function producer()
for n = 1:4
produce(2n)
end
end;

# ...

p = Task(producer);

Then, p is the channel, kind of, but one end is already fixed to a single producer (in Go, everyone can write to a channel, provided that it has the “handle”). We could continue the code above like this:


for s in p
println(s)
end;

which outputs 2, 4, 6, 8. But produce-consume are just commodities for a common pattern: the use of Task, and other details given in Core task operations suggest how these gears are implemented nd the fact that they can be more powerful than it seems (at a price, though…)

## Why?

The reason why I stumbled upon Julia is because of this tutorial, which could be interesting on its own. (Dead link. There are Programming in Julia courses now. Julia is gaining popularity…? Good thing, I think.)

It is somehow impressive. (And it is also impressive that JavaScript V8 engine's performances are better than Python, R, MATLAB and Octave, according to Table 1 in this article — Octave is known to be slow, alas…)

It's not gold all that glitters… and in fact when I tried to plot something, just for the pleasure of it, and typed using PyPlot, I've got an error — annoying.


Value error parsing header in AFM: ItalicAngle -9,9
/usr/lib/pymodules/python2.7/matplotlib/__init__.py:923: UserWarning:  This call to matplotlib.use() has no effect
because the the backend has already been chosen;

...

Warning: error initializing module PyPlot:
PyCall.PyError(msg=":PyImport_ImportModule", T=PyCall.PyObject(o=0xaabbccdd), val=PyCall.PyObject(o=0xaabbccdd), traceback=PyCall.PyObject(o=0xaabbccdd))


It seems a PyLab problem; in fact if I do import pylab from Python, I have a scroll for that Value error parsing header in AFM: ItalicAngle -9,9. Blame a recently installed font? I will see.

## Update

Astonishingly, it seems like few font metric files (afm) used , instead of . as decimal separator! Horrorful. I need to know which tool did it, likely because it picked the italian locale — bad idea, if you have to store decimal numbers in a file (as ASCII string, anyway): those fine arts should be kept for when displaying the number to a user.

I applied the solution suggested here (though I've used Perl with -i.bk). Then import pylab in Python worked and I suppose using PyPlot in Julia will do, too — I'll check later.