(Protocol.UndefinedError) protocol String.Chars not implemented for {"10"}

I’m getting the following error, for the code below it (Chain example from Programming Elixit 1.3):
I’ve double-checked the code and can’t find a discrepancy from the book. Does my newer version of Elixir or Erlang break it? (Elixir 1.5, Erlang 20)

iex(1)> Chain.run(10)

** (Protocol.UndefinedError) protocol String.Chars not implemented for {“10”}
(elixir) lib/string/chars.ex:3: String.Chars.impl_for!/1
(elixir) lib/string/chars.ex:22: String.Chars.to_string/1
chain.exs:20: Chain.create_processes/1
(stdlib) timer.erl:197: :timer.tc/3
chain.exs:25: Chain.run/1

defmodule Chain do

  def counter(next_pid) do
    receive do
      n ->
        send next_pid, n+1

  def create_processes(n) do
    last = Enum.reduce 1..n, self(),
      fn (_, send_to) ->
        spawn(Chain, :counter, [send_to])

    send last, 0 # Start the count by sending zero to the last process.

    receive do
      final_answer when is_integer(final_answer) ->
        "Result is #{{inspect(final_answer)}}"

  def run(n) do
    IO.puts inspect :timer.tc(Chain, :create_processes, [ n ])

You have two curly brackets there! Make it:

"Result is #{inspect(final_answer)}"

Yeah, I spotted that as soon as I posted it. I would have seen it sooner if the editor had a preview button! Thanks!!

1 Like

What editor?! o.O

Well certainly, I should have noticed it first in my editor (Sublime), but I meant if the ElixirForum form had a preview button. ElixirForum actually displayed my code better than the theme I was using in Sublime. :-/

1 Like