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

Richard A. O'Keefe <>
Fri Feb 26 00:52:38 CET 2016



On 26/02/16 1:47 am, Ola Bäckström wrote:
> In Erlang all atoms are put in a global namespace so every reference 
> to, for instance, the atom 'ok' is referring to the same atom in an 
> Erlang node (or even cluster of Erlang nodes). This is indeed what 
> we'd like for that atom. Now in some cases we'd like to register a 
> process or an ETS-table and in fact we'd prefer that it is only 
> referenced by our own source code, aka "global but secret". Here's 
> where name clashes can occur, if foreign modules use the same atom. 
By golly, I must have been urging the introduction of module-local pidnames
for over 20 years by now.

Almost all process registrations should be local to the module that 
registers
them.  I proposed

       -pidname(<atom>).

for declaring a module-locale atomic variable to hold pids.  This would 
be both
safer than the global registry and more efficient.  The global registry 
would
remain for those things that genuinely need to be global.

I'll have to see if I can dig this out.  I thought I'd written it up as 
an EEP,
but it's not in the catalogue.

> Common Lisp resolved this a long time ago, albeit in a - at least for me - complex way. But perhaps the underlying ideas could be used:
> 	* namespaced symbols and
> 	* global keywords
> If I remember correctly the keywords are equivalent to Erlang atoms. The existence of two different sorts of atoms are of fundamental importance to the lisp package system and enables lispers to code in different name spaces.
The Common Lisp solution was in my experience complex and confusing.
Thinking that there are two kinds of atoms is one way of being confused.
One issue, of course, is that Common Lisp packages are not modules.
Very far from it, in fact.



More information about the erlang-questions mailing list