[erlang-questions] [ANN] Annotations 0.0.2

Tim Watson watson.timothy@REDACTED
Wed Feb 1 21:37:37 CET 2012


Still in a very early state, https:://github.com/hyperthunk/annotations now
supports generating additional functions as well as instrumenting existing
(i.e., annotated) ones with before/after/around. As an example of how to
use this, I've written up a sample application that can be used to generate
tedious/boilerplate wrapper functions:
https://github.com/hyperthunk/delegate.

A typical use of delegate is to remove the need to hand code the named
'wrapper' functions for this AST builder that produces a generic
representation of applying a 'binary operator':

-delegate([
    %% pass the generated/target function name
    %% in front of the input arguments
    {args, ['$T', '$I']},
    %% let the generated function(s) have a different arity
    {arity, 2},
    %% generate functions with/for each of these names...
    {delegate, [
           "eq", "gt",
           "gteq", "lt",
           "lteq", "like",
           "contains", "starts_with",
           "ends_with", "matches", "path_exists"
    ]}]).
binop(Op, Axis, {{_,_,_}, _}=Literal) ->
    binop(Op, Axis, {literal, Literal});
binop(Op, Axis, Literal) when is_integer(Literal) orelse
                              is_float(Literal) orelse
                              is_list(Literal) orelse
                              is_record(Literal, semver) ->
    binop(Op, Axis, {literal, Literal});
binop(Op, Axis, {literal, _}=Literal) ->
    {Axis, {operator, Op}, Literal}.


None of this would be possible without the awesome parse_trans library, so
a big thank you is due to Ulf for that really killer tool! Roadmap for
0.0.3 is mainly runtime module/code changes via parse_trans_mod.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120201/a917e5f7/attachment.htm>


More information about the erlang-questions mailing list