Erlang module extension with Smerl

Yariv Sadan yarivvv@REDACTED
Wed Aug 23 03:55:32 CEST 2006


I just added a module extension mechanism for Erlang into Smerl. You
can get your hands on it at

(Direct link:

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."),

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

C3 = smerl:extend(P4, C2),

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


More information about the erlang-questions mailing list