我正在学习Elixir,想知道为什么它有两种类型的函数定义:
使用def定义在模块中的函数,使用myfunction(param1, param2)调用 使用fn定义的匿名函数,使用myfn调用。(param1 param2)
Only the second kind of function seems to be a first-class object and can be passed as a parameter to other functions. A function defined in a module needs to be wrapped in a fn. There's some syntactic sugar which looks like otherfunction(&myfunction(&1, &2)) in order to make that easy, but why is it necessary in the first place? Why can't we just do otherfunction(myfunction))? Is it only to allow calling module functions without parenthesis like in Ruby? It seems to have inherited this characteristic from Erlang which also has module functions and funs, so does it actually comes from how the Erlang VM works internally?
有两种类型的函数并从一种类型转换为另一种类型以便将它们传递给其他函数有任何好处吗?使用两种不同的表示法调用函数是否有好处?