Created
February 28, 2023 10:41
-
-
Save ostinelli/56c7eecfe4e7546a793508f20447d7cd to your computer and use it in GitHub Desktop.
Calling a block passed in a macro in Elixir
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 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