[erlang-questions] Function Reference to Code Tree

Bob Ippolito bob@REDACTED
Wed Jan 23 04:16:59 CET 2013


I don't think what you want is possible, but you can do something similar
if you can require the use of a parse transform. See the ms_transform
implementation used by ets:fun2ms/1.

On Tuesday, January 22, 2013, Tyron Zerafa wrote:

> Erlang:fun_info(F) is returning the function body because it is
> constructed in the shell which essentially passes the entire code tree to
> the erl_eval module for execution. If you call this for a function
> constructed in a module, you won't get this tree.
>
> I need something along these lines that work for functions constructed in
> modules rather than the shell.
>
>
> On Tue, Jan 22, 2013 at 8:05 PM, Gianfranco Alongi <
> gianfranco.alongi@REDACTED <javascript:_e({}, 'cvml',
> 'gianfranco.alongi@REDACTED');>> wrote:
>
>> Is this what you are after?
>>
>> 1> F = fun(X,Y) -> X + Y end.#Fun<erl_eval.12.107821302
>> >2
>>
>> 2> erlang:fun_info(F).
>>   [{pid,<0.31.0>}, {module,erl_eval}, {new_index,3},
>> {new_uniq,<<251,3,184,152,93,16,176,57,2,110,24,202,39,
>> 247,72,160>>}, {index,12}, {uniq,107821302}, {name,'-expr/5-fun-3-'},
>> {arity,2}, {env,[[],       {value,#Fun<shell.7.13242446>},
>> {eval,#Fun<shell.24.85755477>},       [{clause,1,
>>  [{var,1,'X'},{var,1,'Y'}],                [],
>>  [{op,1,'+',{var,1,'X'},{var,1,...}}]}]]}, {type,local}]
>> 3>
>>
>>
>> On Tue, Jan 22, 2013 at 6:21 PM, Tyron Zerafa <tyron.zerafa@REDACTED<javascript:_e({}, 'cvml', 'tyron.zerafa@REDACTED');>
>> > wrote:
>>
>>> F = fun(X,Y) -> X+Y end,
>>>
>>> In the above statement, F is just a function reference. Can I get the
>>> syntax, code tree or anything else from this variable? All I need is to
>>> extract the syntax out of a function reference. Any ideas how I can achieve
>>> this?
>>>
>>> The following convert a fun string into an actual fun. I need something
>>> the other way round, any ideas ??
>>>
>>>
>>> {ok,Tks,_} = erl_scan:string(FunString),
>>> {ok,E} = erl_parse:parse_exprs(Tks),
>>> {value,Funs,_} = erl_eval:exprs(E,[])
>>>
>>> Thanks :)
>>>
>>> _______________________________________________
>>> erlang-questions mailing list
>>> erlang-questions@REDACTED <javascript:_e({}, 'cvml',
>>> 'erlang-questions@REDACTED');>
>>> http://erlang.org/mailman/listinfo/erlang-questions
>>>
>>>
>>
>
>
> --
> Best Regards,
> Tyron Zerafa
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130122/c392f8a3/attachment.htm>


More information about the erlang-questions mailing list