[erlang-questions] question about Variable:fun()
Kirill Zaborsky
qrilka@REDACTED
Mon Jun 27 09:02:01 CEST 2011
>From official docs:
ExprF(Expr1,...,ExprN)
ExprM:ExprF(Expr1,...,ExprN)
In the first form of function calls, ExprM:ExprF(Expr1,...,ExprN), each of
ExprM and ExprF must be an atom or an expression that evaluates to an atom.
(http://www.erlang.org/doc/reference_manual/expressions.html#id75726)
Though it is not clear what "evaluates to atom" may mean for a tuple.
Kind regards,
Kirill Zaborsky
2011/6/27 Andy W. Song <wsongcn@REDACTED>
> 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 <wsongcn@REDACTED> 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 <jack@REDACTED> 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.
>>>
>>
>>
>>
>> --
>> ---------------------------------------------------------------
>> 有志者,事竟成,破釜沉舟,百二秦关终属楚
>> 苦心人,天不负,卧薪尝胆,三千越甲可吞吴
>>
>>
>
>
> --
> ---------------------------------------------------------------
> 有志者,事竟成,破釜沉舟,百二秦关终属楚
> 苦心人,天不负,卧薪尝胆,三千越甲可吞吴
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20110627/6d4b2f02/attachment.htm>
More information about the erlang-questions
mailing list