Skip to content
Simple Metaprogramming for Erlang
Erlang Emacs Lisp Elixir Shell
Branch: master
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin [bin/*.sh] Update shebang and use rebar3_lint Dec 11, 2016
doc Regenerate docs Dec 11, 2016
include initialized smerl Dec 10, 2016
.dir-locals.el [smerl.erl,] Overhaul smerl module and docs Dec 11, 2016
.gitignore [.gitignore] Don't ignore _*; add _dev/scratch.erl Dec 11, 2016
LICENSE [LICENSE] Add Yariv Dec 11, 2016 Regenerate docs Dec 11, 2016
elvis initialized smerl Dec 10, 2016
rebar.config.script [rebar.config.script] Whitespace cleanup Dec 11, 2016
rebar.lock basic tests Dec 10, 2016
rebar3 initialized smerl Dec 10, 2016


Copyright (c) 2006-2007, 2016 AUTHORS

Version: 0.0.1 Downloads Build Status Coverage Status

Simple Metaprogramming for Erlang

Smerl is an Erlang library that simplifies the creation and manipulation of Erlang modules at runtime, using Erlang's capabilities for hot code swapping and abstract syntax tree transformations to do its magic.

New functions can be expressed either as strings of Erlang code or as abstract forms.

For more information, read the Abstract Format section in the ERTS User's guide.


Smerl was inspired by the rdbms_codegen module in the RDBMS application (part of Jungerl) written by Ulf Wiger.

The smerl module was extracted from the abandoned ErlyWeb and patches from ErlyWeb forks.


Define a module foo:

M1 = smerl:new(foo).

Define a function foo:bar/0 using a string of Erlang code:

{ok, M2} = smerl:add_func(M1, "bar() -> 1 + 1.").

... or using the Erlang Abstract Format:

{ok, M2} = smerl:add_func(M1, {function, 1, bar, 0,
                               [{clause, 1, [], [],
                                [{op, 1, '+',
                                 {integer, 1, 1},
                                 {integer, 1, 1}}]}]}).

The abstract format may look more verbose in this example, but it's also easier to manipulate in code.

Compile the foo module and confirm the expected results:

foo:bar(),                                      % returns 2
smerl:has_func(M2, bar, 0).                     % returns true


Section order:

  • Types
  • Macros
  • Callbacks
  • Public API
  • Deprecations
  • Private Parts

Install the git pre-commit hook:

./bin/ install

The pre-commit check can be skipped by passing --no-verify to git commit.


See the AUTHORS file.


Smerl is licensed under The MIT License.


You can’t perform that action at this time.