Reputation: 9360
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 ?
Upvotes: 2
Views: 69
Reputation: 143
It's an order of operations problem. The compiler/runtime doesn't understand what's being returned from Tx(3)
is a function. By adding ()
around it (Tx(3))
, Tx(3)
is evaluated first, is seen as a function, and can then be evaluated again.
Upvotes: 3
Reputation: 11
this is a high order function(like closure)
Tx= fun(A)->
G=fun()->A+33 end,
G
end.
Tx
is a function where arity = 1, and return a function called G
and
G
with arity = 0
Upvotes: 0