Created
May 19, 2017 11:37
-
-
Save thiagoa/1673f8ba044693a4a1b1a0357448ca25 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule FunctionLogger do | |
defmacro __using__(_) do | |
quote do | |
import Kernel, except: [def: 2] | |
import FunctionLogger | |
end | |
end | |
defmacro def(fun_def, do: block) do | |
quote do | |
Kernel.def unquote(fun_def) do | |
fn -> unquote(block) end.() | |
|> FunctionLogger.log | |
end | |
end | |
end | |
def log(value) do | |
IO.inspect "Return value is #{value}" | |
value | |
end | |
end | |
defmodule Example do | |
use FunctionLogger | |
def three do | |
3 | |
end | |
def four do | |
4 | |
end | |
def n(n) do | |
n | |
end | |
end | |
IO.puts Example.n(10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment