2

How do you properly get a character list into Erlang from Elixir?

Suppose I do this is Erlang:

12> [X,Y | R] = "54686973206973206120746573742e".
"54686973206973206120746573742e"

13> X.
53

14> Y.
52

15> io_lib:fread("~16u",[53,52]).                
{ok,"T",[]}

How do make that call correctly from Elixir?

:io_lib.fread("~16u",...)

I have already seen this question: Elixir io_lib call to erlang

But I still seem to get a FunctionClauseError no matter what approach I take to push the list into fread.

Community
  • 1
  • 1
dbryson
  • 6,047
  • 2
  • 20
  • 20

1 Answers1

2

Using single quotes around the format string as described in the linked question seems to work:

iex(1)> :io_lib.fread('~16u', [53,52])
{:ok, 'T', []}
legoscia
  • 39,593
  • 22
  • 116
  • 167
  • Thanks! I was totally focused on the wrong parameter. The key is the format parameter needs to be an Elixir character list. – dbryson Apr 10 '15 at 18:00