Elixir:带有点和嵌套模块的模块名称 - 它们是等价的吗?

时间:2015-08-30 11:21:39

标签: elixir

以下代码是否相同?至于调用模块方法,在两种情况下,都将使用@using (Html.BeginForm()) { @Html.AntiForgeryToken() <div class="form-horizontal"> <h4>Book</h4> <hr /> @Html.ValidationSummary(true, "", new { @class = "text-danger" }) <div class="form-group"> @Html.LabelFor(model => model.BookCheckOutDate, htmlAttributes: new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.EditorFor(model => model.BookCheckOutDate, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.BookCheckOutDate, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.BookReturnDate, htmlAttributes: new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.EditorFor(model => model.BookReturnDate, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.BookReturnDate, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> <div class="col-md-offset-2 col-md-10"> <input type="submit" value="Create" class="btn btn-default" /> </div> </div> </div> //Should come CountryName DropDownlist }

嵌套模块

Utilities.StringUtils.some_method(...)

名称中带点的模块

defmodule Utilities do
   defmodule StringUtils do
   end
end

2 个答案:

答案 0 :(得分:22)

是和否。第一个定义根据模块名称自动定义别名:

defmodule Utilities do
  defmodule StringUtils do
  end

  # Can access the module as StringUtils
end

第二个:

defmodule Utilities.StringUtils do
  # Cannot access the module as StringUtils
end

除此之外,两者定义的代码和模块完全相同。

答案 1 :(得分:3)

是的,两者都被精确地翻译成符号(在Erlang中,模块由其符号引用):

:"Elixir.Utilities.StringUtils"

Erlang中没有真正嵌套的模块,它只是Elixir模拟的东西。