defmodule Q do
stems =
File.read!("stems")
|> String.split("\n", trim: true)
|> Enum.reduce(%{}, fn x, map ->
d = Code.eval_string(x) |> elem(0)
Map.put(map, elem(d, 0), elem(d, 1))
end)
def stems_data(), do: unquote(Macro.escape(stems))
end
stems file example
{"3-d", ["3-d reconstruction"]}
{"abiot", ["abiotic"]}
{"abnorm", ["chromosome abnormality"]}
{"acetyl", ["acetylation", "acetyltransferases"]}
{"acetyltransferas", ["acetyltransferases"]}
It seems that Code.eval_string
does not work in compile-time.
with
** (CompileError) nofile:1: undefined function .../0
(stdlib) lists.erl:1354: :lists.mapfoldl/3
(stdlib) lists.erl:1355: :lists.mapfoldl/3
why?
Is there a way to replace that line with other code?
remark: I am using elixir 1.5.1, OTP 20.0