Funs names in Erlang 17

后端 未结 3 1392
广开言路
广开言路 2021-01-13 00:32

Erlang 17 was released. And according to Erlang OTP 17.0 has been released:

Funs can now be given names

No examples are given.

3条回答
  •  长发绾君心
    2021-01-13 00:54

    Joe Armstrong explains it in his blog post with an example.

    1> F = fun F(0) -> 1; 
               F(N) -> N * F(N - 1) 
           end.
    #Fun
    

    Previously you have to pass in the function as one of the args for anonymous recursive calls. (Think of y-combinator).

    1> F = fun(F, 0) -> 1;
              (F, N) -> N*F(F, N-1)
           end.
    #Fun
    

提交回复
热议问题