Skip to content

Instantly share code, notes, and snippets.

@ostinelli
Created February 28, 2023 10:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ostinelli/56c7eecfe4e7546a793508f20447d7cd to your computer and use it in GitHub Desktop.
Save ostinelli/56c7eecfe4e7546a793508f20447d7cd to your computer and use it in GitHub Desktop.
Calling a block passed in a macro in Elixir
defmodule Foo do
defmacro foo(do: block) do
quote do
res = unquote(block)
IO.inspect(res)
end
end
end
defmodule Use do
require Foo
def test() do
Foo.foo do
1 + 2
end
end
end
# $ elixir test.exs
# 3
Use.test()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment