Parameterized Modules
From Erlang Community
A convenience to passing around a set of values for a module one can use the hidden feature of parameterized modules. Proposed by Richard Carlsson in 'Inheritance in Erlang' and here. It works as follows.
test.erl:
-module(test, [A,B]).
-export([get_a/0, get_b/0]).
get_a() ->
A.
get_b() ->
B.
Shell:
74> c(test).
{ok,test}
75> test:module_info().
[{exports,[{get_a,1},
{get_b,1},
{new,2},
{instance,2},
{module_info,0},
{module_info,1}]},
{imports,[]},
{attributes,[{vsn,[44232957561630721650243949532469790901]},
{abstract,[true]}]},
{compile,[{options,[]},
{version,"4.6.4"},
{time,{2010,2,21,20,52,18}},
{source,"/home/bile/code/erlang/test/test.erl"}]}]
76> T = test:new("This is A", "This is B").
{test,"This is A","This is B"}
77> T:get_a().
"This is A"
78> T:get_b().
"This is B"
79> T:module_info().
** exception error: bad argument
in function erlang:get_module_info/2
called as erlang:get_module_info(test,{test,"This is A","This is B"})
in call from test:module_info/1
80> test:instance("A","B").
{test,"A","B"}
Related Concepts:
More info:

Digg It
Del.icio.us
Reddit
Facebook
Stumble Upon
Technorati

