Search code examples
erlangelixir

Max length of an Erlang/Elixir atom name?


What's the max length of an erlang/elixir atom name? I know there's a a limit on the max number of atoms, but that's also everything that pops up when I search for the max length of an atom. https://www.erlang.org/doc/efficiency_guide/advanced.html

I'm considering building atoms dynamically by concatenating them to form tree-like structures, so I can get hierarchical names for processes. The total number of unique atoms would still be bounded by code size, so I'd still be well below the atom count limit.


Solution

  • Erlang documentation says that limit of characters in atom is 255 (11.2 System Limits)

    Here is an easy way to check

    iex(4)>     Enum.reduce(0..1000, :"", fn atom_length, acc ->
    ...(4)>       try do
    ...(4)>         :"#{acc}x"
    ...(4)>       rescue
    ...(4)>         e ->
    ...(4)>           IO.inspect(atom_length)
    ...(4)>           reraise e, __STACKTRACE__
    ...(4)>       end
    ...(4)>     end)
    255
    ** (SystemLimitError) a system limit has been reached
        :erlang.binary_to_atom("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", :utf8)
        (stdlib 4.1) erl_eval.erl:744: :erl_eval.do_apply/7
        (stdlib 4.1) erl_eval.erl:987: :erl_eval.try_clauses/10
        (elixir 1.13.1) lib/enum.ex:4136: Enum.reduce_range/5