Giter Club home page Giter Club logo

smerl's Introduction

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

smerl's People

Contributors

yurrriq avatar deadtrickster avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.