Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use erlang-examples

Tags:

erlang

I just downloaded Erlang using apt-get onto Ubuntu 10.10. How do I run the examples that come with Erlang (the examples you can get through apt-get install erlang-examples). I tried going to the directory where they were stored and compiling ball.erl, but I got this error:

ball.bea#: error writing file
error
like image 456
TheDude Avatar asked Dec 17 '22 15:12

TheDude


1 Answers

The directory where those examples are stored isn't writeable by normal users. To compile a .erl file, the compiler needs to be able to write out the compiled .beam file.

One way around this is to copy the files to a directory you can write to and compile them there:

$ mkdir erlex
$ cd erlex
$ cp /usr/lib/erlang/lib/gs-1.5.11/examples/src/* .
$ erlc *.erl

You need the erlang-dev package installed for that to work.

You can run the ball example like so:

$ erl -s ball

ball here is the module name, and the Erlang emulator defaults to calling the start/0 function in that module, which is correct in this case.

You don't actually have to compile these examples, however. The Ubuntu erlang-examples package ships with them already compiled:

$ cd /usr/lib/erlang/lib/gs-1.5.11/examples/ebin
$ erl -s ball

After closing the GUI window in each, say q(). to get out of the emulator. This may seem weird to you until you realize that everything about Erlang is designed with long uptimes in mind. The mere fact that the last process the emulator was running has stopped isn't enough reason for the BEAM emulator to shut itself down. Something else might be started in that same emulator later, after all.

like image 149
Warren Young Avatar answered Dec 26 '22 15:12

Warren Young