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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

spawn process

A

pid = spawn(fn -> :timer.sleep(4000) end)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Examine the final AST created by your macro

A

Macro.to_string(some_ast)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly