[erlang-questions] (Non)Parametrized modules, inheritance, and R15B02 issues?

Björn Gustavsson bgustavsson@REDACTED
Mon Oct 8 15:12:03 CEST 2012


On Mon, Oct 8, 2012 at 2:33 PM, Eric Newhuis <enewhuis@REDACTED> wrote:
> Is there a good write-up on parameterized module alternatives anywhere?
>
> - always include an .hrl  and pass a record instance as arg 1 ?
>

It depends on what exactly you are using them for.

Personally, I would define a fun with two args, where the first argument
is a method name and the second argument is a tuple with the arguments.
It would be used like this:


PM = some_module:new(Var1, Var2, Var3),
.
.
.
PM(print, {Arg1,Arg2}),
.
.
.
PM(save, Filename)
.
.
.

And so on.

The function new/3 could be defined like this in the module
some_module:

-record(vars, {var1,var2,var3}).

new(Var1, Var2, Var2) ->
  Vars = vars{var1=Var1,var2=Var2,var3=Var3},
  fun(print, Args) -> print(Args, Vars);
       (save, Args) -> save(Args, Vars)
       .
       .
       .
  end.


-- 
Björn Gustavsson, Erlang/OTP, Ericsson AB



More information about the erlang-questions mailing list