Skip to content

Instantly share code, notes, and snippets.

@alco
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alco/9649919 to your computer and use it in GitHub Desktop.
Save alco/9649919 to your computer and use it in GitHub Desktop.
defmodule M do
defp cases do
[quote do 1 -> 2 end, quote do 3 -> 4 end]
end
defmacrop make_case do
q = quote do
case var!(x) do
0 -> nil
unquote_splicing(cases)
end |> IO.inspect
end
q |> Macro.to_string |> IO.puts
q
end
def test(x) do
make_case
end
end
### Output ###
case(var!(x)) do
0 ->
nil
(1 -> 2)
(3 -> 4)
end |> IO.inspect()
** (CompileError) tes.ex:18: unhandled operator ->
(elixir) case.ex:18: Kernel.|>/2
/Users/alco/Dropbox/home/projects/elixir/numspell/tes.ex:18: M.test/1
/Users/alco/Dropbox/home/projects/elixir/numspell/tes.ex:18: M.make_case/0
/Users/alco/Dropbox/home/projects/elixir/numspell/tes.ex:18: M.test/1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment