elixir 模块名一些参考资料

发布时间 2024-01-04 15:36:45作者: 荣锋亮

elixir 的模块名实际上是一个atom 类型的数据,以下是一些参考资料

参考使用

比如一个mix sup 项目

defmodule EctoDemo.Application do
  use Application
 
  @impl true
  def start(_type, _args) do
    children = [
 
    ]
    # 此处name 实际上就是使用了模块名格式的,因为是一个atom,所以此处可以使用任意名称,只是默认项目使用了EctoDemo.Supervisor 格式的,明确这是一个Supervisor 
    opts = [strategy: :one_for_one, name: EctoDemo.Supervisor]
    Supervisor.start_link(children, opts)
  end
end


实际上可以修改为其他格式的,通过observer 监控看到的信息如下(我修改了name 为EctoDemo.Supervisor.Dalong)

参考资料

https://tylerpachal.medium.com/why-do-erlang-modules-look-like-atoms-in-elixir-9fb2f964dd2b
https://www.oreilly.com/library/view/programming-elixir/9781680500530/f_0060.html
https://stackoverflow.com/questions/29674102/is-elixirs-module-an-atom
https://hexdocs.pm/elixir/1.15.7/Module.html
https://hexdocs.pm/elixir/1.15.7/Supervisor.html
https://elixirforum.com/t/what-are-module-and-function-names-exactly-they-seem-to-be-more-than-atoms/47632/4