Newbee questions about using, compiling and running Erlang module
Simon Chappell
simonpeterchappell@REDACTED
Wed May 11 18:51:02 CEST 2005
Jim,
> Hello....
Hello and welcome to the interesting world of Erlang.
> Thanks for looking and hopefully helping me understand Erlang more. I've
> looked thru the Threads, Tutorials and Docs and I am still a little lost.
Understood. I'm not that much further ahead than you, but have gotten
past the initial confusion stage. I guess that means that I'm confused
at a higher level now!? :-)
> I am running Windows 2003 and have installed Erlang on it. Have Duplicated
> the Banking Server and Clients but do not understand how to run them or test
> them on the system.
Great tutorials.
> I typed the Banking server and clients in thru notepad and saved them as
> .erl modules.
>
> Do I need to compile them first? Is there an IDE to use to compile and
> debug with?
There is no Erlang IDE, and emacs doesn't count either. (An operating
system masquerading as a text editor, if you ask me! ;-)
The way I see it is:
Erlang is a compiled language (escript excepted, but let's not go
there at this time). The practical upshot of that is that you need to
put source code in plain text files with a .erl suffix and then
compile them into an intermediate form (p-code/bytecode?) for the
language runner.
The best way to start any language is, of course, the veritable hello
world program. So, for your edification, I present a version of hello
world that works for me. I make no claims that it's the greatest, but
it does work and I can show you the steps to create, compile and run
it from the command-line. (I like being able to run and test things
from the command-line, so all of the examples that start from the
Erlang shell were a hinderance for me.) I will then be delighted for
the higher-order thinkers on the list to offer feedback as to how it
could be improved.
1. Type in the following code to a text editor, save it as "hello.erl"
and be sure that you get the periods/full stops in the right place.
This gets you a source code version of hello world.
%%
%% hello.erl
%%
-module(hello).
-export([start/0]).
start() ->
io:fwrite("hello, world\n").
2. To compile hello.erl, type the following command while in the same
directory as the file:
erlc hello.erl
3. Now let's see what we got. Take a look in the directory and you
should see a file called "hello.beam" if all has gone well.
4. Now, we need to run this file and enjoy the fruits of our labour.
Type the following command:
erl -noshell -s hello -s init stop
5. You should be staring at the words "hello, world" on a line on your
console at this point.
A couple of points to note:
* If you're familiar with C, the start/0 is the equivalent of main().
* The "-noshell" tells Erlang that you want this to run without the
Erlang REPL shell.
* The "-s init stop" makes sure that Erlang performs appropriate
startup and shutdown activities before and after it executes your
masterpiece.
> Is there a Document available that will help me to do a simple project from
> start to finish and see it run.....do tests on it...debug it?
>
> I've looked at the 4 day course and the "Tutorial number 1
>
> Thank you
I hope that this helps. I must admit that it took quite a bit of
digging and lurking on the mailing list before I got that figured out
myself. I'm glad to share.
I needed this information for my personal open-source project that I'm
working on. It's a multi-language test runner and I was trying to add
Erlang to the list of languages it understands. It explicitly needs to
be able to compile and run programs from the command-line and also to
capture their standard out.
http://simonpeter.com/technology/software/zadok/
Simon
More information about the erlang-questions
mailing list