6
votes

For example,

x = "foo"
%{foo => 1}

**(CompileError) iex:11: illegal use of variable x in map key

Obviously it's building the map at compile time, which could be more efficient, but why doesn't it fall back to a runtime constructor like most languages with data structure literals? Interested to know if there's something about the characteristics of maps in Elixir that I'm missing.

Adding to the confusion is this Google Groups message from over a year ago, where José Valim says:

Variable keys in maps will be available in the next Erlang release.

But that was a year ago, now, and I can't find any other references to this. To what Erlang version was he referring? I'm running 18 right now and it definitely still isn't in place.

1

1 Answers

14
votes

Erlang 18 added support for it and we need to update Elixir to leverage that. Therefore, we plan to support it on the next Elixir version, Elixir v1.2.