[erlang-questions] Process declarations

Joe Armstrong <>
Thu Oct 5 09:31:18 CEST 2006


Process declarations:

Thinking out loud....

Proposal 1 (Radical)
==========

Do away with spawn. Replace with a process keyword:


Today
=====

-module(foo).
-export([bar/1]).

bar(X) ->
    receive
        X -> ...
    end.

-module(bar).
...

g(X, Y) ->
    Pid = spawn(foo, bar, [X]),
    ...

Tomorrow??
==========

-module(foo).
-export([bar/1]).

process bar(X) ->
    receive
       X -> ...
    end.

-module(bar).
...

g(X, Y) ->
    Pid = foo:bar(X),
    ...

Why?

So that we can name processes. Things without names we cannot talk about.
So if we write:

    f(X, Y) -> ...
    process g(X, Y) -> ...

    Then evaluating

    A = f(X, Y) works as usual

    But

    Z = g(X, Y)

    *always* results in Z being a Pid

Proposal 2 (Conservative)
=========================

-module(glurk).

-export([foo/1]).

-process([bar/2]).

foo(X) ->
    1.

bar(X, Y) ->
    spawn(fun() -> 1 end).

Extend the parser to understand -process attributes (as above)

Note this implies that the function is exported from the module,
which would put an end to the horribly practise of artificially
exporting functions that are known to be targets of spawns.

 /Joe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20061005/150f5a23/attachment.html>


More information about the erlang-questions mailing list