Skip navigation.

Blu3c4t Journal

randomly blu3c4t's logs on the shell...

Little about Erlang Programming Language

Erlang programming language ??? What's that ???....
Ok... I'll be explain to you... Erlang is a general-purpose concurrent programming language and runtime system. The sequential subset of Erlang is a functional language, with strict evaluation, single assignment, and dynamic typing. It was designed by Ericsson to support distributed, fault-tolerant, soft-real-time, non-stop applications. It supports hot swapping so code can be changed without stopping a system.

Is the language a proprietary or an open source one ??? Hmmm...in the beginning Erlang was originally a proprietary language within Ericsson, but it was released as open source in 1998. Erlang is named after A. K. Erlang (a Danish mathematician, statistician and engineer, who invented the fields of traffic engineering and queueing theory). Although, It is sometimes thought that its name is an abbreviation of "Ericsson Language", owing to its heavy use inside Ericsson.

Well... now, i'm gonna tell to you how to install Erlang's compiler and program in Erlang language on FreeBSD system.

1. Install the Compiler...
[blu3c4t@mahardhika ~]$ whereis erlang
erlang: /usr/ports/lang/erlang
[blu3c4t@mahardhika ~]$ cd /usr/ports/lang/erlang
[blu3c4t@mahardhika /usr/port/lang/erlang]$ su
Password:
[root@mahardhika /usr/port/lang/erlang]# make install clean

And Erlang's compiler will be install on your system, it's simple right ?!!

2. Let's coding !!!

Erlang have a command interpreter or shell, to start Erlang's shell, just type like this on your shell:
[blu3c4t@mahardhika ~]$ erl
Erlang (BEAM) emulator version 5.5.1 [source] [async-threads:0] [hipe] [kernel-poll:false]

Eshell V5.5.1 (abort with ^G)
1>

for try the shell at first time, let's type :

1> 3 + 14 .
17
2>

You'll notice that the Erlang shell has numbered the lines that can be entered, (as 1> 2>) and from that simple calculation it give you correctly answer (3 + 14 is 17). Also notice that you have to add "." when finishing entering code and then push enter/return. There many more editing commands in the shell, just read the manual (there're compressed manual at /usr/ports/distfiles/erlang ). Now let's try a more complex calculation.

2> (88 - 17) / 3 * 11 .
260.333

To exit the Erlang's system and shell, just type Control-C, you'll see the output:

BREAK: (a)bort (c)ontinue (p)roc info (i)nfo (l)oaded
(v)ersion (k)ill (D)b-tables (d)istribution

a
[blu3c4t@mahardhika ~]$

Type "a" to leave the Erlang's shell or just type "halt () ." at the shell.

Ok... now you can put Erlang's code of your program at a file and save as anything.erl (the file will be in *.erl name), example:

[blu3c4t@mahardhika ~]$ mkdir erlang_exercise
[blu3c4t@mahardhika ~]$ cd erlang_exercise
[blu3c4t@mahardhika ~/erlang_exercise]$ cat > first.erl
-module(first).
-export([double/1]).

double(X) ->
3 * X .
^C
[blu3c4t@mahardhika ~/erlang_exercise]$

Now, let's run the simple program.

[blu3c4t@mahardhika ~/erlang_exercise]$ erl
Erlang (BEAM) emulator version 5.5.1 [source] [async-threads:0] [hipe] [kernel-poll:false]

Eshell V5.5.1 (abort with ^G)
1>c(first) .
{ok, first}

The {ok, first} tells you that the compilation was OK. If it said "error" instead, you just must check the error message, get fix it and try to compile again.

Run the program:
2> first:double(10) .
30

What that's program means ??

-module(first).

This tells us that the module is called "first".

-export([double/1]).

Says that the module first contains a function called double which takes one argument (X in our example) and that this function can be called from outside the module tut.

4> first:double(10) .

Means call function double in module first with argument “10”.


Ok... for now, i just can give you that as introduction to Erlang Programming Language, if you wanna learn more about Erlang you can using google to find some deep Erlang's tutorials or you just can buy the book about it.

Just visit these links:
http://www.erlang.org/
http://www.erlang.se/