announcing Smerl: Simple Erlang Metaprogramming library

Yariv Sadan yarivvv@REDACTED
Tue Aug 15 17:10:54 CEST 2006


FYI, I just added a function, smerl:for_file for creating a new module
from an Erlang source file. This should help working with scripts
rather than compiled modules.

Cheers
Yariv

On 8/14/06, Yariv Sadan <yarivvv@REDACTED> wrote:
> Hi,
>
> Digging through Ulf Wiger's rdbms_codegen.erl module in Jungerl, I
> discovered Erlang's wonderful capabilities for runtime code generation
> and manipulation. As great as these capabilities are, I think they are
> far from obvious to the non-expert programmer. That's why I created
> Smerl, simple library for (runtime) Erlang metaprogramming.
>
> To read more about Smerl and to download it, visit my blog:
> https://yarivsblog.com/articles/2006/08/14/smerl-simple-metaprogramming-for-erlang.
>
> Here's a direct download link:
> https://yarivsblog.com/files/smerl.erl
>
> Here's a quick example of how to use Smerl:
>
> test_smerl() ->
>   C1 = smerl:new(foo).
>   {ok, C2} = smerl:add_func(C1, "bar() -> 1 + 1.").
>   smerl:compile(C2),
>   foo:bar().   % returns 2
>
> Smerl also lets you work with abstract Erlang forms. The 3rd line of
> the above example can be rewritten as
>
> {ok,C2} = smerl:add_func(C1, {function,1,bar,0,
>            [{clause,1,[],[],
>              [{op,1,'+',{integer,1,1},{integer,1,1}}]}]).
>
> Smerl allows you to both create new module in runtime and to
> manipulate existing modules by adding and removing functions.
>
> If you have any comments, problems or suggestions, please let me know!
>
> Best regards,
> Yariv
>



More information about the erlang-questions mailing list