[erlang-questions] Erlang way for process-as-library?

Vlad Dumitrescu vladdu55@REDACTED
Tue Apr 24 09:11:12 CEST 2007


On 4/24/07, ok <ok@REDACTED> wrote:
> On 6 Feb 2007, at 2:17 pm, Robert Baruch wrote:
> > Now, the next question I have is: is there an Erlang way to forbid
> > "ordinary users" from calling the server's callback functions
> > directly (e.g. init, terminate, and so on), while allowing gen_server
> > access to them?
> Too many years ago I proposed adding
>    -export_to(Module, [F1/N1,...Fk/Nk]).
> to Erlang (rather like Eiffel {} export controls) so that some functions
> could be provided to one specific module without providing them to every
> module.  If memory serves me correctly, I also sketched an
> implementation.

This gives me an uneasy feeling: it means that a process should be
aware of the possible clients...

Another way to to the same thing is to have separate modules export
different interfaces and just delegating to the base module. This can
be implemented as a parse transform where a declaration in the lines
   -interface(Base_Module, [Fn/Nn...]).
would be expanded to the required function definitions.

Alternatively, the base module could contain
    -interface(Interface_Module, [Fn/Nn...]).
and the Interface_Module module would be generated dynamically in its entirety.

Of course, the base module can still be called directly, but it shouldn't be.

best regards,

More information about the erlang-questions mailing list