I am trying to insert a dynamically named variable using the following code:
defmodule Revive do
defmacro revive(key, val) do
quote do
var!(unquote(key)) = unquote(val)
end
end
end
require Revive
Revive.revive(:user, "Aku")
Error:
** (ArgumentError) expected a variable to be given to var!, got: :user
(elixir) lib/kernel.ex:3496: Kernel."MACRO-var!"/3
(elixir) expanding macro: Kernel.var!/1
iex:6: (file)
expanding macro: Revive.revive/2
iex:6: (file)
Is this even possible in Elixir?