Erlang module extension with Smerl

Yariv Sadan <>
Wed Aug 23 03:55:32 CEST 2006


Hello,

I just added a module extension mechanism for Erlang into Smerl. You
can get your hands on it at http://code.google.com/p/smerl/.

(Direct link: http://smerl.googlecode.com/svn/trunk/smerl.erl).

Here's a quick example:

P1 = smerl:new(parent),
{ok, P2} = smerl:add_func(P1, "add(A, B) -> A+B."),

%% 'false' indicates to not export the function
{ok, P3} = smerl:add_func(P2, "subtract(A, B) -> A-B.", false),

{ok, P4} = smerl:add_func(P3, "multiply(A,B) -> A*B."),
smerl:compile(P4),

C1 = smerl:new(child),
{ok, C2} = smerl:add_func(C1, "multiply(A,B) -> throw(not_allowed)."),

C3 = smerl:extend(P4, C2),
smerl:compile(C3),

8 = parent:add(3,5),
{'EXIT', {undef, _}} = begin catch parent:subtract(4,3) end,
6 = parent:multiply(3, 2),
11 = child:add(2,9),
not_allowed = begin catch child:multiply(5,3) end,
{'EXIT', {undef, _}} = begin catch child:subtract(4,2) end.


The full story is here

http://yarivsblog.com/articles/2006/08/22/new-module-extension-in-erlang-with-smerl

Best,
Yariv



More information about the erlang-questions mailing list