# \_\_using\_\_ macro with option

**URL:** <https://forum.elixirforum.com/t/using-macro-with-option/50443>\
**Category:** Questions\
**Tags:** metaprogramming, macros, \_\_using\_\_\
**Created:** [September 22, 2022, 11:13am UTC](https://forum.elixirforum.com/t/using-macro-with-option/50443 "2022-09-22T11:13:00Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![mruoss](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/mruoss/32/34561_2.png) [@mruoss](https://forum.elixirforum.com/u/mruoss)\
**Post date:** [September 25, 2022, 6:56am UTC](https://forum.elixirforum.com/t/using-macro-with-option/50443/7 "2022-09-25T06:56:59Z")

</div>

> [@Eiji](#):
>
> I have used `atom` as it’s best for what I called `feature_name` as those in `apply_feature/1` are known at compile-time. You can use strings, integers and every other data that you can write pattern-matching for.

Not maps. Or structs. You can’t expand those to their original value either. You’d have to call `Code.eval_quoted()` which is discouraged inside macros, no?

I’d like come back to my original question. I have changed the example to take a map. It does not make much sense like this and could be done better, but it is a simple example to show the case with a map as option value:

```elixir
defmodule UsedModule do
  defmacro __using__ (opts) do
    quote do
      if unquote(opts[:with_extra]) do
        def extra(), do: "with extra"
      else
        def extra(), do: "no extra"
      end
    end
  end
end

```

```elixir
defmodule UsingModuleWithExtra, do: use UsedModule, config: %{with_extra: true}
defmodule UsingModuleNoExtra, do: use UsedModule

```

```elixir
iex> UsingModuleWithExtra.extra()
"with extra"

iex> UsingModuleNoExtra.extra()
"no extra"

```

See the passed option is expected to be a map. Which cannot be expanded to its original value. You have to unquote them inside a quote block (right?). So my question was, if you would - in this case where the argument requires unquoting - implement the macro like I did above or rather put the if condition inside the generated function like this:

```elixir
def extra() do
  if Keyword.get(opts, :config, %{})[:with_extra], 
    do: "with extra", 
    else: "no extra"
end

```

---

_[View the full topic](https://forum.elixirforum.com/t/using-macro-with-option/50443)._
