[erlang-questions] Why we need a -module() attribute?

Joe Armstrong erlang@REDACTED
Fri Feb 19 21:52:50 CET 2016

While on the subject of modules ...

I think there should be 'anonymous modules' and registered modules
(just like processes):

For processes:

    Pid = spawn(fun() -> ... end)

Creates a process, but only the process which created the process can say

    Pid ! Message

Other process do not know the value of Pid so they can't send any
messages to Pid.

This is inconvenient so we can say register(foo, Pid) and thereafter *any*
process can say `foo ! Message`

I would like to see:

    Mod = load_code(Bin)

after which the parent can say Mod:func(....) and register(Name, Mod)
and then *any* process can call foo (just like registered processes)

With such a mechanism we could declare and use private modules which are not
globally visible.

(The same should be true for ets tables and ports) - also Modules
should be linkable
and sent exit signals to their link set when deleted.

Just make everything behave like processes.



On Fri, Feb 19, 2016 at 6:00 PM, Fred Hebert <mononcqc@REDACTED> wrote:
> On 02/19, Loïc Hoguin wrote:
>> You never had the error that the module name doesn't match the file name?
> Frankly the only times I got the error was when I was either:
> 1. Making copies of modules for benchmarks or comparisons and forgetting to
> change the names. This error was necessary since I couldn't run 3 modules
> all with the same name without issue. Much appreciated
> 2. Moving files around and I forget to rename the module. I tend to like
> things to be in order and I appreciate the reminder that renaming a file
> means I should probably rename the module.
> It's annoying that it's mandatory, but I can't really think of too many
> cases where I want to look for a module, and must find it in a
> differently-named file. I guess I could use grep/awk/ack to move around, but
> I quite like just opening a file with the right name.
> I always thought of the feature as a net positive given it forces me to keep
> things clean and consistent.
> One module per file is something I'm more open to argue about, but filename
> must match the module name is definitely a plus for me.
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions

More information about the erlang-questions mailing list