Search code examples
erlangreturn-typehigher-order-functions

Why i can not call returned method directly


I have the following curious case in Erlang:

Tx=fun(A)->G=fun()->A+33 end,G end.

I do not understand why i can't call the returned method directly , and need to store it in a variable first:

Tx(3)().   ->  1: syntax error before: '(' //why does this not work ?

Var=Tx(3)     //and this
Var()         // works

I can not call a method that is returned ?


Solution

  • Wrap the returned fun into brackets:

    (Tx(3))().