Created
July 30, 2015 08:16
-
-
Save tallakt/d2b883bb8884f1ad9739 to your computer and use it in GitHub Desktop.
Tuplify Elixir problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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