title: How do I create an atom dynamically in Erlang?
body: <p>I am trying to register a couple processess with atom names created dynamically, like so:</p>
  
  <pre><code>keep_alive(Name, Fun) -&gt;
      register(Name, Pid = spawn(Fun)),
      on_exit(Pid, fun(_Why) -&gt; keep_alive(Name, Fun) end).
  
  monitor_some_processes(N) -&gt;
      %% create N processes that restart automatically when killed
      for(1, N, fun(I) -&gt;
                               Mesg = io_lib:format("I'm process ~p~n", [I]),
                               Name = list_to_atom(io_lib:format("zombie~p", [I])),
                               keep_alive(Name, fun() -&gt; zombie(Mesg) end)
                       end).
  
  for(N, N, Fun) -&gt; [Fun(N)];
  for(I, N, Fun) -&gt; [Fun(I)|for(I+1, N, Fun)].
  
  zombie(Mesg) -&gt;
      io:format(Mesg),
      timer:sleep(3000),
      zombie(Mesg).
  </code></pre>
  
  <p>That <code>list_to_atom/1</code> call though is resulting in an error:</p>
  
  <pre><code>43&gt; list_to_atom(io_lib:format("zombie~p", [1])).
  ** exception error: bad argument
       in function  list_to_atom/1
          called as list_to_atom([122,111,109,98,105,101,"1"])
  </code></pre>
  
  <p>What am I doing wrong?
  Also, is there a better way of doing this?</p>