Skip to Main Content
Mastering Elixir
book

Mastering Elixir

by André Albuquerque, Daniel Caixinha
July 2018
Intermediate to advanced content levelIntermediate to advanced
574 pages
14h 7m
English
Packt Publishing
Content preview from Mastering Elixir

Famous (un)quotes

Let's now investigate what unquote does and see its role on the interaction of the quote and unquote dynamic duo. Until now we only injected quoted expressions on the caller module (recall the code block injected by the Demo.simple/1 macro injected on the Playground module).

As you will see, the unquote/1 macro will be extensively used, almost whenever we use a macro. The unquote/1 macro can only be used inside a quote block and lets us inject the value of a variable defined on an outer scope.

Let's continue with the previous Demo module, but this time we want the param variable to be used inside the quote block returned by the Demo.simple/1 macro:

iex> defmodule Demo do...>   defmacro simple(param) do...> IO.puts "Inside ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Testing Elixir

Testing Elixir

Andrea Leopardi, Jeffrey Matthias

Publisher Resources

ISBN: 9781788472678Supplemental Content