Can messages be sent to processes interactively?
Claes Wikstrom
klacke@REDACTED
Fri May 21 22:53:24 CEST 1999
>
> I've been doing a lot of sequential programming in Erlang, but have just
> started getting into concurrency. It seems very obvious and
> straightforward.
>
> I wrote a quickie test process so I can start it up and send messages to
> it interactively, just so I know that all is well:
>
> -module(sample).
> -export([start/0]).
>
> start() -> spawn(sample, server, []).
>
> server() ->
> receive
> stop -> ok;
> Msg ->
> io:fwrite("message received: ~w\n", [Msg]),
> server(N)
> end.
>
And yet another little error, there is no function
called sample:server/0 nor sample:server/1 *exported*
from the module.
It might seem pretty idiotic that any function that is spawned
need to be exported but that is the way it is.
(applies to apply/3 too !!!)
So, change
> -export([start/0]).
to
-export([start/0, server/0]).
Personally I like the
-compile(export_all)
switch while I'm developing, this way I need not bother
about that at that stage.
Cheers
/klacke
PS. There's a bit of one of my favourite topics in here -- namely
software archeology. Why is it like this. The obvious thing would
be to spawn a fun instead of a tripple M:F/A
start() ->
spawn(fun() -> server() end).
????
More information about the erlang-questions
mailing list