Skip to content

Instantly share code, notes, and snippets.

@rramsden
Last active December 28, 2015 07:18
Show Gist options
  • Save rramsden/7462933 to your computer and use it in GitHub Desktop.
Save rramsden/7462933 to your computer and use it in GitHub Desktop.
# http://elixir-lang.org/docs/stable/Module.html#moduledoc
defmodule M do
@before_compile __MODULE__
defmacro __before_compile__(_env) do
quote do
def hello, do: "world"
end
end
end
---------------------
Erlang R16B (erts-5.10.1) [source] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]
Interactive Elixir (0.11.2-dev) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> defmodule M do
...(1)> @before_compile __MODULE__
...(1)>
...(1)> defmacro __before_compile__(_env) do
...(1)> quote do
...(1)> def hello, do: "world"
...(1)> end
...(1)> end
...(1)> end
** (UndefinedFunctionError) undefined function: M.__before_compile__/1
M.__before_compile__(Macro.Env[module: M, file: "iex", line: 1, function: nil, aliases: [], context: nil, requires: [IEx.Helpers, Integer, Kernel, Kernel.Typespec, Record], functions: [{Kernel, [!: 1,
!=: 2, !==: 2, *: 2, +: 1, +: 2, ++: 2, -: 1, -: 2, --: 2, /: 2, <: 2, <-: 2, <=: 2, ==: 2, ===: 2, =~: 2, >: 2, >=: 2, abs: 1, atom_to_list: 1, binary_part: 3, binary_to_float: 1, binary_to_integer: 1,
binary_to_integer: 2, binary_to_term: 1, binary_to_term: 2, bit_size: 1, bitstring_to_list: 1, byte_size: 1, exit: 1, float_to_binary: 1, float_to_binary: 2, float_to_list: 1, float_to_list: 2, function_e
xported?: 3, hd: 1, inspect: 1, inspect: 2, integer_to_binary: 1, integer_to_binary: 2, integer_to_list: 1, integer_to_list: 2, iolist_size: 1, iolist_to_binary: 1, is_alive: 0, is_atom: 1, is_binary: 1,
is_bitstring: 1, is_boolean: 1, ...]}], macros: [{Kernel, [&&: 2, ..: 2, <>: 2, @: 1, access: 2, and: 2, apply: 2, apply: 3, atom_to_binary: 1, binary_to_atom: 1, binary_to_existing_atom: 1, binding: 0, b
inding: 1, binding: 2, case: 2, cond: 1, def: 1, def: 2, def: 4, defdelegate: 2, defexception: 2, defexception: 3, defimpl: 2, defimpl: 3, defmacro: 1, defmacro: 2, defmacro: 4, defmacrop: 1, defmacrop: 2, defmacrop: 4, defmodule: 2, defoverridable: 1, defp: 1, defp: 2, defp: 4, defprotocol: 2, defrecord: 2, defrecord: 3, defrecordp: 2, defrecordp: 3, destructure: 2, div: 2, elem: 2, if: 2, in: 2, is_exception: 1, is_range: 1, is_record: 1, is_record: 2, is_regex: 1, ...]}], context_modules: [M], macro_aliases: [], vars: [], lexical_tracker: nil]) src/elixir_module.erl:402: :elixir_module."-eval_callbacks/5-fun-0-"/4 src/elixir_module.erl:401: :elixir_module."-eval_callbacks/5-fun-1-"/6 lists.erl:1313: :lists.foreach/2 src/elixir_module.erl:154: :elixir_module.eval_form/5 src/elixir_module.erl:74: :elixir_module.compile/5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment