Monday, July 28, 2008

Learning Erlang

I have started to learn Erlang, it is very different from programming languages i have used previously.

The strenghts of erlang are:
Pattern matching
The pattern matching is not what you would expect, early in the book it was introduced as assignment, but was later explained to be pattern matching.
1> X=1.
1
2> [X,Y]=[1,2].
[1,2]
Also variables can be assigned only once, so the 2nd expression succeeded only because we attempted to match 1 against X, had we tried to use a different value we would have gotten an error:

3> X=2.

=ERROR REPORT==== 29-Jul-2008::07:33:24 ===
Error in process <0.31.0> with exit value: {{badmatch,2},[{erl_eval,expr,3}]}

** exited: {{badmatch,2},[{erl_eval,expr,3}]} **

Assign-once variables makes parallelism very easy
In erlang there are no mutex locks because variables are never changed after their first assignment. Which completely eliminates the concept of race conditions! As other processes cannot change your data there are no unexpected side effects from multi-threading

I'm still learning, so i will post an update once i get further.


You're only as young as the last time you changed your mind.
- Timothy Leary