-
-
Save cjbottaro/fd332faa7a28cb35506e to your computer and use it in GitHub Desktop.
var!/2
This file contains hidden or 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 | |
var!(foo, Foo) = "foo" | |
unquote(block) | |
end | |
end | |
end | |
defmodule Runner do | |
require Foo | |
def fun do | |
Foo.foo do | |
IO.puts var!(foo, Foo) | |
end | |
IO.puts var!(foo, Foo) | |
end | |
def run do | |
IO.puts var!(foo, Foo) # (CompileError) expected var "foo" (context Foo) to expand to an existing variable or be part of a match | |
end | |
end | |
Runner.fun | |
Runner.run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment