[erlang-questions] Finding a way to get function name from local function reference

Sergey S ad.sergey@REDACTED
Wed Jan 21 01:03:27 CET 2009


Hello.

I'm going to write a simple benchmark utility taking function
references and then writing results with corresponding function names.

What I'm looking for is the way to get readable function name at runtime.

Here is pseudo code:

get_name(fun some_mod:some_fun/0) -> some_fun
get_name(fun some_fun/0)                  -> some_fun

I took a look at "erl -man erlang" to find out what I can use in this
case. erlang:fun_info(Fun, name) seems useful but it works only for
exported function references:

% erlang:fun_info/2 will return the readable name: {name, some_fun}.
That is what I want to get.
erlang:fun_info(fun some_module:some_fun/0, name)

But it doesn't work for local function references (I've checked):

% Note that 'some_module' is omitted. This function will return
something like {name,'-test/0-fun-0-'} which is incomprehensible to me
erlang:fun_info(fun some_fun/0, name).

With local function references I have to use something other... Is
there a simple way to get the name of the function?

--
Sergey



More information about the erlang-questions mailing list