小编Ven*_*ham的帖子

Elixir:定义地图的问题

我有一个预定义的Maps,其中有一个数字作为键及其值,我尝试通过在CL中像下面这样创建映射来正常工作,但是当我通过代码文件执行时会抛出类似错误。

我说错了

** (Protocol.UndefinedError) protocol String.Chars not implemented for %{1 => "I", 4 => "IV", 5 => "V", 9 => "VI", 10 => "X", 40 => "XL", 50 => "L", 90 => "XC", 100 => "C", 400 => "CD", 500 => "D", 900 => "CM", 1000 => "M"} of type Map
    (elixir) lib/string/chars.ex:3: String.Chars.impl_for!/1
    (elixir) lib/string/chars.ex:22: String.Chars.to_string/1
    (elixir) lib/io.ex:654: IO.puts/2
Run Code Online (Sandbox Code Playgroud)

当我尝试定义预定义的键值时。

defmodule DecimalToRoman do
  def convert(decimal) do
    roman_table = %{
      1 => "I",
      4 => "IV",
      5 => "V",
      9 …
Run Code Online (Sandbox Code Playgroud)

elixir

1
推荐指数
1
解决办法
52
查看次数

标签 统计

elixir ×1