[erlang-questions] parameterized modules and OO

Richard Carlsson richardc@REDACTED
Wed May 30 15:20:54 CEST 2007


Torbjorn Tornkvist wrote:
> So I was thinking, would it be possible for a parameterized module
> to modify its own module attributes ?
> [...]
> So would this be possible to add without too much hassle ?
> 
> Cheers, Tobbe
> (NB: I'm not saying this is good or bad, I'm not even proposing
> this, I'm just curious to hear if it would be easy/hard/impossible to 
> add this functionality.)

- The current runtime system does not support runtime changes to the
attributes (the module_info stuff) of a module.

- The attributes are per-loaded-module ("class members" in OO
terminology), and what you probably want is a table of attributes per 
module instance. That table should thus be created when you call 'new'.
There are at least two possible ways of hiding the table creation:

   1: Specify the abstract module with N parameters, the last one being
      the per-instance table, and insert a hand-written function new/M
      where M=N-1, which calls the autogenerated new/N with a freshly
      created table.

   2: Separate the actual abstract module implementation and its
      interface: give the abstract module some other name, and let the
      interface module have a new/M function which calls the new/N
      function of the abstract module with the extra parameters.

   /Richard




More information about the erlang-questions mailing list