defmodule Test do
defmacro test({:==, _, [left, right]} = _) do
quote do
left = unquote(left)
right = unquote(right)
if left == right do
IO.puts "Equal!"
else
IO.puts "Not Equal!"
end
end
end
def run do
test 1 == 1
test 1 == 2
end
end
Test.run~>elixir test.exs
test.exs:15: warning: this clause cannot match because a previous clause at line 15 always matches
test.exs:16: warning: this check/guard will always yield the same result
Equal!
Not Equal!defmodule Test do
defmacro test({:==, _, [left, right]} = _) do
quote do
left = unquote(left)
right = unquote(right)
case (left == right) do
true ->
IO.puts "Equal!"
_ ->
IO.puts "Not Equal!"
end
end
end
def run do
test 1 == 1
test 1 == 2
end
end
Test.run>elixir test1.exs
Equal!
Not Equal!
--
You received this message because you are subscribed to the Google Groups "elixir-lang-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-ta...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-talk/d3669fc9-ba7b-40f6-b597-849590c2326f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.