How to eval erlang atoms in Elixir

Hi guys,

i am writing an Elixir module that reads a file containing a list of Erlang tuples like this:

{{<<"key1">>, <<"key2">>, key3}, value1}

i would like to turn that tuple in a elixir variable, so i tried running

Code.eval_string(my_string)

but i got into this error


error: undefined variable "key3"
  nofile:1

** (CompileError) cannot compile code (errors have been logged)

Because of course key3 is treated as a variable… do you have any suggestion?
Maybe something smarter than putting quotes around key3 and value1?

thanks in advance
Paolo

Quick and dirty:

# Note that the character list must be termitated with a dot
{:ok, tokens, _} = :erl_scan.string(input_as_character_list)
{:ok, term} = :erl_parse.parse_term(tokens)
6 Likes