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

Bob Ippolito bob@REDACTED
Thu Apr 26 02:06:46 CEST 2007


On 4/24/07, Vlad Dumitrescu <vladdu55@REDACTED> wrote:
> Hi,
>
> 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
> of
>    -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.

I think that this is more or less a solved problem with parameterized
modules [1]. The gen_server usage would have to change slightly, but
they do a good job of encapsulating a module and making it easily/only
available to anyone with the parameterized reference.

[1] http://www.erlang.se/workshop/2003/paper/p29-carlsson.pdf

-bob



More information about the erlang-questions mailing list