Specify arity using only or except when importing function on Elixir

后端 未结 2 579
再見小時候
再見小時候 2020-12-20 14:04

I\'m studying Elixir and when I use only or except operators when importing functions from a module I need to specify an arity number. Why?

<
2条回答
  •  清酒与你
    2020-12-20 15:04

    Functions in Erlang and Elixir are uniquely identified by module/name/arity. In order to import/exclude the correct function, you need to specify all three parts. Another way of understanding this is to consider the case of capturing function references, e.g. &Map.get/2.

    Even if two functions share the same name, they are actually completely different functions to the VM. In order to reference the correct one, you have to correctly identify the function you wish to call, hence the need to specify all three components with only, except.

提交回复
热议问题