【问题标题】:Is there a way I can return a functions definition in Elixir有没有办法可以在 Elixir 中返回函数定义
【发布时间】:2016-03-31 14:24:59
【问题描述】:

给我一​​个模块:

defmodule Foo do
  def bar(baz) do
    IO.puts baz
  end
end

有什么办法可以退货:

def bar(baz) do
  IO.puts baz
end

我发现我可以加载模块的整个定义:

Foo.__info__(:compile) |> List.last |> elem(1) |> File.read |> elem(1)

但理想情况下,我很乐意做类似的事情

Foo.bar/1.__definition__
#=> def bar(baz) do\n  IO.puts baz\nend\d

【问题讨论】:

  • 我认为您需要深入研究 erlang - 请参阅 stackoverflow.com/questions/5250587/…
  • 所以你问是否可以反编译函数定义?我认为答案是否定的。
  • 我仍然抱有希望,如果失败了,我可能不得不考虑自己编写。

标签: elixir


【解决方案1】:

Elixir 是一种编译语言。在运行时源代码不再存在,它已被编译为 BEAM 字节码。在运行时没有函数的源代码级表示供您的代码检查或检索。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-19
    • 1970-01-01
    • 1970-01-01
    • 2020-12-24
    • 2021-11-09
    • 2023-03-21
    • 1970-01-01
    相关资源
    最近更新 更多