small medium large xlarge

Generic-user-small
05 Apr 2017, 17:02
Olivier Boudry (1 post)

I don’t understand why we need what looks like a double unquote of the tag variable in the html_step2.exs macro. We create a macro for each html tag from the file. In the macro, we use tag = unquote(tag) which in my understanding replaces tag with it’s unquoted/injected value, but then it’s unquoted again in the quote do: tag(unquote(tag)).

for tag <- @tags do
  defmacro unquote(tag)(do: inner) do
    tag = unquote(tag)
    quote do: tag(unquote(tag), do: unquote(inner))
  end
end

I’m certainly misunderstanding it as it compiles and works. But it’s confusing to me.

You must be logged in to comment