为什么我不能直接调用返回的方法

Why i can not call returned method directly

我在 Erlang 中有以下奇怪的案例:

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

不明白为什么不能直接调用返回的方法,需要先保存在变量中:

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

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

我无法调用返回的方法?

把返回的fun包在括号里:

(Tx(3))().

这是一个操作顺序问题。 compiler/runtime 不明白从 Tx(3) 返回的是一个函数。通过在 (Tx(3)) 周围添加 ()Tx(3) 首先被求值,被视为一个函数,然后可以再次求值。

这是一个高阶函数(类似于闭包)

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

Tx 是一个函数,其中 arity = 1,而 return 是一个名为 G

的函数

G 元数 = 0