Skip to content

Instantly share code, notes, and snippets.

@talentdeficit
Last active October 23, 2017 02:43
Show Gist options
  • Save talentdeficit/14e809b548e0be99db8767eed271910e to your computer and use it in GitHub Desktop.
Save talentdeficit/14e809b548e0be99db8767eed271910e to your computer and use it in GitHub Desktop.
19:41:20 [ alisdair@charmander ] $ iex
Erlang/OTP 20 [erts-9.0] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
Interactive Elixir (1.5.1) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> defmodule A do
...(1)> def a(), do: true
...(1)> end
{:module, A,
<<70, 79, 82, 49, 0, 0, 3, 96, 66, 69, 65, 77, 65, 116, 85, 56, 0, 0, 0, 81, 0,
0, 0, 9, 8, 69, 108, 105, 120, 105, 114, 46, 65, 8, 95, 95, 105, 110, 102,
111, 95, 95, 9, 102, 117, 110, 99, ...>>, {:a, 0}}
iex(2)> defmodule B do
...(2)> def a(), do: def b(), do: true
...(2)> end
** (ArgumentError) cannot invoke def/2 inside function/macro
(elixir) lib/kernel.ex:4623: Kernel.assert_no_function_scope/3
(elixir) lib/kernel.ex:3567: Kernel.define/4
(elixir) expanding macro: Kernel.def/2
iex:3: B.a/0
iex(3)> defmodule C do
...(3)> IO.inspect def c(), do: true
...(3)> end
{:c, 0}
{:module, C,
<<70, 79, 82, 49, 0, 0, 3, 100, 66, 69, 65, 77, 65, 116, 85, 56, 0, 0, 0, 81,
0, 0, 0, 9, 8, 69, 108, 105, 120, 105, 114, 46, 67, 8, 95, 95, 105, 110, 102,
111, 95, 95, 9, 102, 117, 110, 99, ...>>, {:c, 0}}
iex(3)>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment