Skip to content

Instantly share code, notes, and snippets.

@jc00ke
Last active March 25, 2017 16:29
Show Gist options
  • Save jc00ke/caef080fb8a40f14b092f24461914d27 to your computer and use it in GitHub Desktop.
Save jc00ke/caef080fb8a40f14b092f24461914d27 to your computer and use it in GitHub Desktop.
defmodule Foo do
defmacro foo_macro(i) do
quote do
unquote(i)
end
end
def bar(foo_macro(1) = i), do: IO.puts(i)
def bar(foo_macro(2) = i) do
IO.puts "This better be 2: #{i}"
end
end
Foo.bar(1)
# => 1
Foo.bar(2)
# => This better be 2: 2
Foo.bar(3)
#** (FunctionClauseError) no function clause matching in Foo.bar/1
# foo.exs:8: Foo.bar(3)
# (elixir) lib/code.ex:370: Code.require_file/2
@jc00ke
Copy link
Author

jc00ke commented Mar 25, 2017

@wobh yeah, that was my position, but others at the meeting didn't think it works work that way. This is a small POC to show them it actually worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment