If any language could be said to be ideally placed to deal with the challenges of the next 10 years it's Erlang. Designed from the ground up to take advantage of parallel and multi-core architectures, and natively supporting distributed systems coding, Erlang is a valuable addition to your programming skill set.

Originally designed by Ericsson as a proprietary language for controlling telecoms applications, Erlang was released to the public in 1998 under an open source licence. It's been gaining in popularity over the past few years largely due to its support for cheap, quick and disposable processes, which make adding and using concurrency in your programming easier and more efficient. Popular programs implemented in Erlang include ejabberd, the instant messaging server behind jabber.org, and Wings3D, a full featured 3D modelling application.

Why Erlang?

  • Parallel programming -- It's the next big thing, and no language does it better than Erlang. Creating processes is easy, cheap and clean and manipulating them is not much harder. Best of all, since inter-process communication is conducted entirely by message passing and there is no shared state, many concurrency problems just go away.
  • It's functional -- without the concurrency, Erlang behaves as a near pure functional language. Functional languages eschew state, which means that bugs have less chance of having unexpected side effects. The result is more robust and secure code.
  • It's free -- Erlang is backed by open standards and free implementations of the interpreter. That means you can start working, learning and developing in Erlang for absolutely nothing.
  • It's tested -- having been deployed in real world applications by Ericsson since the late '80s, you can be sure Erlang has got proven reliability and fault tolerance.

Where can you get it?

Erlang.org is the first place to look. There is a source distribution for Linux, UNIX and Macintosh systems, and a Windows binary.

Interactive Mode

Like many modern languages, Erlang comes with an interactive prompt, which allows you to test your program without having to change and recompile each time you want to test a new component or function. You can try it out to do some simple math operations -- Erlang can handle numbers pretty much as big as you like, so don't be afraid to try those really long equations you've always wanted to:

nickg@nickg-desktop:~$ erl
Erlang (BEAM) emulator version 5.5.2 [source] [async-threads:0] [kernel-poll:false]

Eshell V5.5.2 (abort with ^G)
1> 10+5.
15
2> 15*3.
45
3> 2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2
*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2
*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2
*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2
*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2
*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2
*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2
*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2
*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2.
99895953610111751404211111353381321783955140565279076827493022708011895642232499843849795298031743077114461795885011
932654335221737225129801285632

Each statement must be punctuated by a full-stop.

Functions

Erlang is a functional language, and so control flow is conducted using functions, pattern matching and recursion. Syntax in Erlang is very close to that of the declarative language Prolog. For example, type the following in a file called hello.erl.

-module(hello).
-export([hello/0]).

hello() -> io:format("Hello World~n").

This defines a module called hello, which exports (meaning, makes visible to code which imports the module) one function, also called hello, which takes no inputs. The hello function uses the format function from the io module, which is similar to printf, to print a string to the console. The "~n" is the sequence to print a newline, similar to "\n" in some other languages.

Load it into the interactive interpreter and try it out:

nickg@nickg-desktop:~/erlang$ erl
Erlang (BEAM) emulator version 5.5.2 [source] [async-threads:0] [kernel-poll:false]

Eshell V5.5.2  (abort with ^G)
1> c(hello).
{ok,hello}
2> hello:hello().
Hello World
ok

For longer functions, you separate statements with a comma, and only use the full-stop to denote the end of the function:

hello() -> 
	io:format("Hello "),
	io:format("World~n").

Erlang also supports pattern matching on function inputs, which allows you to write different versions of a function depending on the parameters. This allows you to write recursive solutions cleanly, like so:

countdown(0) -> 
	io:format("Blast Off!~n");
countdown(X) -> 
	io:format("~w~n", [X]),
	countdown(X-1).

2> test:countdown(10).
10
9
8
7
6
5
4
3
2
1
Blast Off!
ok

You can further enhance function input pattern matching by using guards -- which let you specify criteria for the inputs beyond simple patterns. For example, our countdown function above can only handle positive numbers, but can be called with any number at all. We can use guards to protect it, and only let correct inputs through:

countdown(0) -> 
	io:format("Blast Off!~n");
countdown(X) when X > 0 -> 
	io:format("~w~n", [X]),
	countdown(X-1).

Alternatively, we could extend the countdown function to work for both positive and negative numbers by adding another version of the function:

countdown(0) -> 
	io:format("Blast Off!~n");
countdown(X) when X > 0 ->
        io:format("~w~n", [X]),
        countdown(X-1);
countdown(X) when X < 0 -> 
        io:format("~w~n", [X]),
        countdown(X+1).

Related links

Comments

1

Jens Moller - 18/08/07

Is there a 'run-time' environment? How would you package Erlang programs for general distribution under Windows, OS X or Linux? The Erlang Language reference guide never seems to discuss application deployment.

» Report offensive content

2

Elmer Fittery - 10/10/08

Hum, 'run-time' environment?

I don't know if there is one. I have only dealt with building toy programs to teach myself erlang. I will research it.

» Report offensive content

3

Elmer Fittery - 10/10/08

It seems that you must install the erlang base system to be able to run a erlang application.

I see no indication that you compile application code (ala c/c++) but rather have to run the code using the installed Erlang base environment.

This is like Java.

We all use web browsers that can view Java based web pages. It requires that you have Java installed on your computer.

» Report offensive content

Leave a comment

You must read and type the 6 chars within 0..9 and A..F

* indicates mandatory fields.

3

Elmer Fittery - 10/10/08

It seems that you must install the erlang base system to be able to run a erlang application. I see no indication ... more

2

Elmer Fittery - 10/10/08

Hum, 'run-time' environment? I don't know if there is one. I have only dealt with building toy programs to teach ... more

1

Jens Moller - 18/08/07

Is there a 'run-time' environment? How would you package Erlang programs for general distribution under Windows, OS X or Linux? The ... more

Log in


Sign up | Forgot your password?

  • Staff Microsoft shows off IE9 preview

    This week, highlights from Microsoft's MIX10 conference and more in the Roundup. Read more »

    -- posted by Staff

  • Chris Duckett IE9's H.264 vote killed Ogg

    In a split decision by the judges, the winner of the W3C/WHATWG video codec consensus is H.264, taking home the future of video playback on the internet while loser Ogg goes home with nothing but thoughts of what might have been. Read more »

    -- posted by Chris Duckett

  • Staff Google launches Apps Marketplace

    Google launches and app store, while Mozilla plans to re-write its open-source license. More of this week's news in the Roundup. Read more »

    -- posted by Staff

What's on?

  • Optus Deal

    Broadband + home phone + PlayStation®3 in a single package price!