How to use erlang-examples

落花浮王杯 提交于 2019-12-12 11:34:46

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/5495756/how-to-use-erlang-examples

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!