[erlang-questions] Re: implementing annotation in erlang

Ulf Wiger ulf.wiger@REDACTED
Thu Sep 10 08:41:39 CEST 2009


paweł kamiński wrote:
> to prepare something like
> cmdCallbackList()->
> [{"cmdDevSetTime",setTime,1},{"cmdFpSetStatus",setStatus,2}].
> 
> I need to build
> {function,19,cmdCallbackList,0,
>      [{clause,19,[],[],
>           [{cons,20,
>                {tuple,20,
>                    [{atom,20,"cmdDevSetTime"},
>                     {atom,20,setTime},
>                     {integer,20,1}]},
>                {cons,20,
>                    {tuple,20,
>                        [{atom,20,"cmdFpSetStatus"},
>                         {atom,20,setStatus},
>                         {integer,20,2}]},
>                    {nil,20}}}]}]}
> 
> is there a way to construct code blocks in more elegant way, something like
> create_fun(LineNo, Name, Arity, Body, ..)-> would produce function block
> create_tuple(LineNo, Tuple)
> create_list(...)
> and so on

To begin with, using

erl_parse:abstract([{"cmdDevSetTime",setTime,1}...])

is a significant simplification. When generating a constant
term in a parse_transform, it is easiest to just build the
term, and then calling abstract/1 to turn it into forms.

I wouldn't worry about the line numbers. If you do, there is
always abstract/2. Most of the time when dealing with parse
transforms, it isn't worth it, and the compiler doesn't
really care.

BR,
Ulf W

-- 
Ulf Wiger
CTO, Erlang Training & Consulting Ltd
http://www.erlang-consulting.com





More information about the erlang-questions mailing list