Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transform quoted elixir code to a code string

I have a situation where I am expecting some quoted elixir code to be an atom. If the wrong quoted code is passed in I want to raise an error and show what the wrong code was.

Simplest way to show what I need is with an example.

quoted_code = quote do: %{}
"%{}" = some_func(quoted_code)
like image 649
Peter Saxton Avatar asked Mar 15 '23 15:03

Peter Saxton


1 Answers

You can achieve this with Macro.to_string/2

Macro.to_string(quote do: %{}) #=> "%{}"
like image 71
michalmuskala Avatar answered Mar 25 '23 06:03

michalmuskala