[erlang-questions] question about Variable:fun()

Andy W. Song <>
Mon Jun 27 08:37:44 CEST 2011


I guess I found the answer, see following code
-module(abc).
-export([joke/0, test_fun/1]).

test_fun({abc, _, _}) ->
    io:format("Great, ~n").

joke() ->
    V = {abc, "tst", "filed2"},
    V:test_fun().

If I call abc:joke() it will eventaully call test_fun/1, with V as the
parameter. I would like to see some official documentation though.

Thanks
Andy

On Mon, Jun 27, 2011 at 1:28 PM, Andy W. Song <> wrote:

> In my case the variable is a record like V = {rec, field1, field2} where
> rec is indeed a module name with fun() defined in it. So it seems that
> calling to this record will in turn call the first element?
>
> Thanks
> Andy
>
>
> On Mon, Jun 27, 2011 at 12:35 PM, Jack Moffitt <> wrote:
>
>> > New to Erlang. I saw some program with statement such as V:fun() which I
>> > can't find from Joe's Erlang book. I know module:fun() is calling a
>> function
>> > defined in a module. But do this to a variable is confusing. Does that
>> > variable define a function, and how?
>>
>> It is probably bound to an atom, like in this example:
>>
>> X = dict,
>> D = X:new().
>>
>> jack.
>>
>
>
>
> --
> ---------------------------------------------------------------
> 有志者,事竟成,破釜沉舟,百二秦关终属楚
> 苦心人,天不负,卧薪尝胆,三千越甲可吞吴
>
>


-- 
---------------------------------------------------------------
有志者,事竟成,破釜沉舟,百二秦关终属楚
苦心人,天不负,卧薪尝胆,三千越甲可吞吴
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20110627/3e5ba254/attachment.html>


More information about the erlang-questions mailing list