defmodule My do
defmacro unless(condition, _do_block = [do: expression]) do
_unless(condition, expression)
end
defmacro unless(condition, expression) do
_unless(condition, expression)
end
defp _unless(condition, expression) do
quote do
if !unquote(condition), do: unquote(expression)
end
end
end

Sincerely, I don’t like this unquote inside the quote block. I prefer to use Code.eval_quoted to evaluate the condition.
Dave, what do you think ? I think is less complicated than the one in your example “macros/myif.ex”

As the exercise saids: “You’re allowed to use the regular if expression in it.”

defmodule MyMacro do
defmacro myunless(condition, clauses) do
do_clause = Keyword.get(clauses, :do, nil)
else_clause = Keyword.get(clauses, :else, nil)
quote do
if unquote(condition) do
unquote(else_clause)
else
unquote(do_clause)
end
end
end
end
defmodule TestMacro do
require MyMacro
MyMacro.myunless true do
IO.puts("This will never be seen")
else
IO.puts("This will be seen")
end
end