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

README.md

Smerl

Copyright (c) 2006-2007, 2016 AUTHORS

Version: 0.0.1

Hex.pm Hex.pm 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.

Origins

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.

Examples

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:

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

Contributing

Section order:

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

Install the git pre-commit hook:

./bin/pre-commit.sh install

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

AUTHORS

See the AUTHORS file.

License

Smerl is licensed under The MIT License.

Modules

smerl
You can’t perform that action at this time.