some_dynamic_atom = :"prefix_#{name}"
quote do
Task.Supervisor.async_nolink(Tasks.Chain, &unquote(some_dynamic_atom)/0)
end
# Should become
Task.Supervisor.async_nolink(Tasks.Chain, &prefix_smth/0)
I need to create a dynamic function in Elixir macro and pass its name to the Task
I made a dynamic function, however the macro above gives me an error:
invalid args for &, expected an expression in the format of &Mod.fun/arity, &local/arity or a capture containing at least one argument as &1, got: :prefix_smth / 0
One possible solution is to use fn -> unquote(some_dynamic_atom)() end, but my benchmarks show, that using an anonymous wrapper noticeably slows down the execution.
&__MODULE__.unquote(some_dynamic_atom)/0works FWIW. Not sure why it throws that error without module.