Skip to content

Instantly share code, notes, and snippets.

@tallakt
Created July 30, 2015 08:16
Show Gist options
  • Save tallakt/d2b883bb8884f1ad9739 to your computer and use it in GitHub Desktop.
Save tallakt/d2b883bb8884f1ad9739 to your computer and use it in GitHub Desktop.
Tuplify Elixir problem
$ elixir tuplify.exs
Returned from macro:
def(tuplify_from_macro(x)) do
{unquote(Macro.var(:x, nil))}
end
** (CompileError) tuplify.exs:21: function x/0 undefined
(stdlib) lists.erl:1336: :lists.foreach/2
tuplify.exs:14: (file)
(elixir) lib/code.ex:307: Code.require_file/2
$ erl -version
Erlang (ASYNC_THREADS) (BEAM) emulator version 6.4.1
$ elixir -v
Elixir 1.0.4
defmodule M do
defmacro def_tuplify do
result = quote(unquote: false) do
def tuplify_from_macro(x) do
{unquote(Macro.var :x, nil)}
end
end
IO.puts "Returned from macro:\n#{result |> Macro.to_string}"
result
end
end
defmodule A do
require M
def tuplify(x) do
{ unquote(Macro.var :x, nil) }
end
M.def_tuplify
end
IO.puts "testing results"
IO.inspect A.tuplify(:ok)
IO.inspect A.tuplify_from_macro(:ok)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment