...

/

Other Ways to Run Code Fragments

Other Ways to Run Code Fragments

Learn different ways to run code fragments.

Code.eval_quoted

We can use the function Code.eval_quoted to evaluate code fragments, such as those returned by quote.

iex> fragment = quote do: IO.puts("hello") 
{{:.,[],[{:__aliases__,[alias: false],[:IO]},:puts]},[],["hello"]} 

iex> Code.eval_quoted fragment
hello
{:ok,[]}
...