I’m trying to make a macro to do pattern matching on maps but I have a problem.
I have a list of members for my map in the form [key1: value1, key2: value2, ...]
where each value is an AST representation of the term.
For example :
defmacro my_macro(_) do
quote do
# This variable is dynamically generated and must be inside a quote expression
members = [a: {:_, [], Elixir}, b: 42]
def my_function(unquote({:%{}, [], USE_MEMBERS_VAR_HERE})), do: :ok
end
end
I am looking for this macro to create the following function
def my_function(%{a: _, b: 42} = args) do
# Do some operations
end
The problem is that I don’t know how to inject the content of the variable members
into the AST tuple.