[erlang-questions] Invoking function as record-member

Jeroen Koops <>
Thu Nov 6 09:17:49 CET 2008


Thanks all!

On Wed, Nov 5, 2008 at 10:29 PM, Tamas Nagy <> wrote:

> Hi!
>
> Try it like this:
>
> (X#test.my_fun)(1).
>
> Regards,
>        Tamas
>
> On 5 Nov 2008, at 21:03, Jeroen Koops wrote:
>
>  Hello,
>>
>> I have a record with a member to which I assign a function:
>>
>> $ cat test.hrl
>> -record(test, { my_fun }).
>> $
>>
>> and, from the Erlang shell:
>>
>> 18> rr("test.hrl").
>> [test]
>> 19> X=#test{my_fun = fun(X) -> X*2 end}.
>> #test{my_fun = #Fun<erl_eval.6.49591080>}
>>
>> When I try to invoke the function, the shell complains with a syntax
>> error:
>>
>> 20> X#test.my_fun(1).
>> ** 1: syntax error before: '(' **
>>
>> Of course, it does work when first assigning the record-member to a
>> variable:
>>
>> 21> Y=X#test.my_fun.
>> #Fun<erl_eval.6.49591080>
>> 22> Y(1).
>> 2
>>
>> Is there some syntactical subtlety I'm missing out on, or is this
>> something I should just not want?
>>
>> Thanks,
>>
>> Jeroen
>>
>> _______________________________________________
>> erlang-questions mailing list
>> 
>> http://www.erlang.org/mailman/listinfo/erlang-questions
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20081106/a35634b7/attachment.html>


More information about the erlang-questions mailing list