【发布时间】:2020-07-17 14:44:09
【问题描述】:
这里不行。使用Macro.expand/2 也无济于事。
defmodule ExBs.Component do
defmacro defcomp(name, opts) do
func = Keyword.get(opts, :func)
IO.inspect(func)
func.("foo")
end
end
defmodule ExBs.Foo do
import ExBs.Component
defcomp(:foo,
func: &Phoenix.HTML.Link.link/2
)
end
这是 IEx 输出:
[{:__aliases__, [line: 24], [:Phoenix, :HTML, :Link]}, :link]
** (BadFunctionError) expected a function, got: nil
expanding macro: ExBs.Component.defcomp/2
有可能吗?
【问题讨论】: