[erlang-questions] Invoking function as record-member

Tamas Nagy lestat@REDACTED
Wed Nov 5 22:29:05 CET 2008


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
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions




More information about the erlang-questions mailing list