Can a macro generate functions iteratively from list of atoms?

Notice that the code above is not a macro. It does make use of unquote fragments.

I often like to use for comprehensions in cases like this. Same outcome, just an alternative approach:

defmodule F do
  for name <- [:item_a, :item_b, :item_c] do
    def unquote(name)(param), do: {:ok, param}
  end
end
5 Likes