Convert quoted elixir code to line of code

I have a situation where I expect some cited elixir code to be an atom. If the wrong cited code is passed, I want to raise an error and show what was the wrong code.

The easiest way to show what I need with an example.

quoted_code = quote do: %{}
"%{}" = some_func(quoted_code)
+4
source share
1 answer

You can achieve this with Macro.to_string/2

Macro.to_string(quote do: %{}) #=> "%{}"
+6
source

Source: https://habr.com/ru/post/1609579/


All Articles