parse_trans/examples/ex_pmod.erl
Ulf Wiger ae7163f3db For fun, implemented a 'pmod' parse transform.
See examples/pmod.erl and examples/ex_pmod.erl
This works similarly to OTP's parameterized modules, which they are
now saying that they will drop. Since they drop the compiler support,
a slightly different notation is needed.

-pmod_vars([V1, V2, ...]). % defines the 'global' variables.
-pmod_funs([F1/A1, ...]).  % defines which functions are to be exported.

The functions listed in -pmod_funs/1 are transformed to take an extra
argument, and a new(V1, V2, ...) function is added and exported.

Example:

Eshell V5.9  (abort with ^G)
1> c(ex_pmod).
{ok,ex_pmod}
2> M = ex_pmod:new(a,b).
{ex_pmod,{a,b}}
3> M:b(x,y).
{x,y,a,b}
2012-10-12 19:34:03 +02:00

15 lines
151 B
Erlang

-module(ex_pmod).
-compile({parse_transform, pmod}).
-pmod_vars(['A', 'B']).
-pmod_funs([a/1,
b/2]).
a(X) ->
X.
b(X,Y) ->
{X,Y,A,B}.