Skip to content

Instantly share code, notes, and snippets.

@udzura
Created April 13, 2012 01:01
Show Gist options
  • Save udzura/2372484 to your computer and use it in GitHub Desktop.
Save udzura/2372484 to your computer and use it in GitHub Desktop.
test elixir macro var!!!!!
defmodule Hygiene do
defmacro interference do
quote do: var!(a) + var!(b) + var!(c)
end
end
defmodule HygieneTest do
def go do
require Hygiene
a = 10
b = 20
c = 30
Hygiene.interference
end
end
defmodule Hygiene do
defmacro no_interference do
quote do: a + b + c
end
end
defmodule HygieneTest do
def go do
require Hygiene
a = 10
b = 20
c = 30
Hygiene.no_interference
end
end
$ iex test1.ex
Interactive Elixir (0.9.0.dev) - press Ctrl+C to exit
Erlang R15B01 (erts-5.9.1) [source] [64-bit] [smp:8:8] [async-threads:0] [hipe] [kernel-poll:false]
iex> HygieneTest.go
60
iex> require Hygiene
[]
iex> Hygiene.interference
** (UndefinedFunctionError) undefined function: Elixir.IEx.a/0
Elixir.IEx.a()
erl_eval.erl:572: :erl_eval.do_apply/6
erl_eval.erl:398: :erl_eval.expr/5
src/elixir.erl:95: :elixir.eval_forms/3
/private/tmp/homebrew-elixir-HEAD-DzdP/lib/elixir/iex.ex:63: Elixir.IEx.do_loop/1
iex> a = 1
1
iex> b = 2
2
iex> c = 3
3
iex> Hygiene.interference
6
iex> a = 10
10
iex> Hygiene.interference
15 # is 10 + 2 + 3
iex>
BREAK:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment