Metaprogramming Syntax Flashcards
1
Q
Override hygiene
A
defmodule Setter do defmacro bind_name(string) do quote do !var(name) = unquote(string) end end end
2
Q
spawn process
A
pid = spawn(fn -> :timer.sleep(4000) end)
3
Q
Define a way to extend a module using Elixir’s common API of use and using
A
defmodule Assertion do
defmacro \_\_using\_\_(_options) do quote do import unquote(\_\_MODULE\_\_)
def run do IO.puts "Running the tests..." end end end end
defmodule MathTest do
use Assertion
end
4
Q
Examine the final AST created by your macro
A
Macro.to_string(some_ast)