Slide 25
Slide 25 text
summon = fn args ->
defmodule Hoge do
vars = Enum.map(args, fn arg ->
arg
|> String.to_atom
|> Macro.var(__MODULE__)
end)
def say(unquote_splicing(vars)) do
IO.inspect unquote(vars)
end
end
end
summon.(["arg1", "arg2", "arg3"])
Hoge.say(1, 2, 3)
# [1, 2, 3]
unquote_splicingを使えば複数引数の関数も生成できる
引数は Macro.var/2 を使ってASTにしておく必要がある