Elixir 中的多行注释

Multiline comment in Elixir

大多数语言都允许块注释和多行命令。

例如,HTML 中的多行注释如下所示:

<!-- 
Warning, brave programmer:
Here be dragons.
-->

在 Elixir 中,我找到的最接近的东西来自 EEx (docs)。

EEx smartengine <% #comments %> 似乎已从源代码中丢弃,即使它们是多行的。但是,这只是一种解决方法。

Elixir 是否具有多行注释功能,或指示编译器从已编译的 .beam 文件中丢弃文本的方法?

Elixir 没有多行注释。

但是,多行注释的一个非常常见的用例是记录模块和函数,对此您可以使用 module attributes @doc and @moduledoc together with heredocs.

defmodule MyModule do
  @moduledoc """
  This module is great at X
  """

  @doc """
  Frobnicates the given string.
  """
  def frobnicate(s) do
  end
end

宏可以在一定程度上帮助这里:

defmodule Comment do
  defmacro comment(_text) do
  end
end

defmodule TestComment do
  import Comment

  comment """
  Module
  Comment
  """

  def func do
    comment """
    Function
    Comment
    """
  end
end

您可以简单地使用模块属性进行多行注释,不需要宏。我通常将以下内容用于 documenting/commenting 私有函数:

@docp """
This is my
multi line
comment
"""

我尝试只使用“””来快速注释代码 Python,而不将其变成文档

"""
def some_function() do
  some_code    
end
"""