[erlang-questions] Function to syntax tree

Sean Cribbs seancribbs@REDACTED
Mon May 3 14:59:01 CEST 2010


I did something similar a couple months ago, but taking a fun() and
turning it into a module function with smerl:
http://seancribbs.com/tech/2010/01/12/smerl-for-awesome/

On Mon, May 3, 2010 at 2:53 AM, Ulf Wiger
<ulf.wiger@REDACTED> wrote:
>
> Perhaps this code snippet might be of some help?
>
> http://www.erlang.org/cgi-bin/ezmlm-cgi/4/31984
>
> I have not tried to see whether it still works, though.
>
> BR,
> Ulf W
>
> bokner wrote:
>>
>> Hi,
>>
>> erl_scan and erl_parse can turn function represented by string into
>> AST. For example,
>>
>> 1> {ok, S, _} = erl_scan:string("fun(X) -> X+1 end."),
>> 1> {ok, P} = erl_parse:parse_exprs(S),
>> 1> [F] = P, erl_syntax:type(F).
>> fun_expr
>>
>> My question is: how do I do the same, but  with the function itself
>> instead string representation? I.e.,
>>
>> F = fun(X) -> X +1 end,
>>
>> AST = <some code turning F into AST>,
>> fun_expr = erl_syntax:type(AST).
>>
>> Thanks,
>> Boris
>>
>>
>> ________________________________________________________________
>> erlang-questions (at) erlang.org mailing list.
>> See http://www.erlang.org/faq.html
>> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
>>
>
>
> --
> Ulf Wiger
> CTO, Erlang Solutions Ltd, formerly Erlang Training & Consulting Ltd
> http://www.erlang-solutions.com
> ---------------------------------------------------
>
> ---------------------------------------------------
>
> WE'VE CHANGED NAMES!
>
> Since January 1st 2010 Erlang Training and Consulting Ltd. has become ERLANG
> SOLUTIONS LTD.
>
> www.erlang-solutions.com
>
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
>
>


More information about the erlang-questions mailing list