Metaprogramming Elixir (Pragprog)

Hello all, recently this book came into my attention, namely I am trying to do a macro that creates a module dynamically. Let’s say, something like this:

defmodule Name do
  @opaque t :: {:name, String.t()}

  @spec new(val :: String.t()) :: t
  def new(val) when is_binary(val), do: {:name, val}

  @spec extract(name :: t) :: String.t()
  def extract({:name, val}), do: val

  @spec name?(data :: any) :: boolean()
  def name?({:name, val}) when is_binary(val), do: true
  def name?(_data), do: false

  @spec is_name(data :: any) ::
          {:__block__ | {:., [], [:andalso | :erlang, ...]}, [],
           [{:= | {any, any, any}, [], [...]}, ...]}
  defguard is_name(value)
           when is_tuple(value) and elem(value, 0) == :name and is_binary(elem(value, 1))
end

which would be generated by invoking:

deftype Name, String.t() 

Now I have checked the mini-video for the book:

And as an intro, it covers a lot. But after checking the index I have some questions:

  • does the book cover my specific use case? (does it teach how to dynamically generate modules?)
  • does the book cover how to include typespecs in the generated code?
  • How many pages does the book have?