Skip to content

Instantly share code, notes, and snippets.

@cjbottaro
Created January 12, 2016 04:07
Show Gist options
  • Save cjbottaro/fd332faa7a28cb35506e to your computer and use it in GitHub Desktop.
Save cjbottaro/fd332faa7a28cb35506e to your computer and use it in GitHub Desktop.
var!/2
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