Elixir: MapSet.new() not working

Created on 13 Apr 2019  路  3Comments  路  Source: elixir-lang/elixir

Environment

  • Elixir & Erlang/OTP versions (elixir --version):
    Erlang/OTP 21 [erts-10.3.2] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]

Elixir 1.8.1 (compiled with Erlang/OTP 20)

  • Operating system:

Ubuntu 18.04

Current behavior

Trying to create a new MapSet named T as in the docs.

Current output is:

iex(1)> T = MapSet.new()
** (MatchError) no match of right hand side value: #MapSet<[]>
    (stdlib) erl_eval.erl:453: :erl_eval.expr/5
    (iex) lib/iex/evaluator.ex:257: IEx.Evaluator.handle_eval/5
    (iex) lib/iex/evaluator.ex:237: IEx.Evaluator.do_eval/3
    (iex) lib/iex/evaluator.ex:215: IEx.Evaluator.eval/3
    (iex) lib/iex/evaluator.ex:103: IEx.Evaluator.loop/1
    (iex) lib/iex/evaluator.ex:27: IEx.Evaluator.init/4

Expected behavior

If I follow the docs, apparently this structure is not being created correctly. Is it something wrong with my Elixir/Erlang version?

In case the docs need updates, I would be happy to submit a pull request or something like that :)

Most helpful comment

Hi @LucianaMarques!

Variables in Elixir must start in lowercase. Therefore, T is not a variable, but rather an atom. So you are trying to match two values that can never be equal, like this:

iex(1)> 1 = 2
** (MatchError) no match of right hand side value: 2

Which is why you get such error. If you rename the variable to t (lowercase), then it should work!

All 3 comments

Hey @LucianaMarques, the problem happening here is that you're assigning the result of MapSet.new() to T. As you might know, in Elixir and Erlang = is for pattern matching and assignment, but in Elixir T is a module name (that is, an atom). You might come from Erlang and that's why you used T or it might just be a typo. In any case, the MatchError is happening because the mapset doesn't match with the atom T.

This will work:

iex> t = MapSet.new()
#MapSet<[]>

Hi @LucianaMarques!

Variables in Elixir must start in lowercase. Therefore, T is not a variable, but rather an atom. So you are trying to match two values that can never be equal, like this:

iex(1)> 1 = 2
** (MatchError) no match of right hand side value: 2

Which is why you get such error. If you rename the variable to t (lowercase), then it should work!

Wow guys, thank you for such a quick response! It's working now 馃榿

Was this page helpful?
0 / 5 - 0 ratings