开发者

How to use erlang-examples

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 d开发者_如何学Pythonirectory where they were stored and compiling ball.erl, but I got this error:

ball.bea#: error writing file
error


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜