Printing a list in Elixir gives string -


this question has answer here:

i'm running code below adds numbers in list 10. however, getting list of chars.

result = enum.map([1, 2, 3], fn x -> x + 10 end)

result \w\f\r

if change + * code works fine. result = enum.map([1, 2, 3], fn x -> x + 10 end) returns [10, 20, 30] expected.

however, moment change 10 32, encounter similar error returns ' @'

any idea means , how fix it? thanks

in elixir, char list (a value between 2 single quotes 'like this') list of numbers. so, when have list of numbers of them can written characters (within ascii range), iex print them such you.

iex(1)> 'hello' 'hello' iex(2)> [104, 101, 108, 108, 111] 'hello' 

you still have list of numbers, , can still other operations on if list of numbers, such as

iex(3)> [104, 101, 108, 108, 111] == 'hello' true iex(4)> enum.map 'hello', fn x -> x * 10 end [1040, 1010, 1080, 1080, 1110] 

if, within iex, want see numeric values of list, can append non-viewable character list, such 0, force iex display numeric list instead of char list.

iex(5)> [104, 101, 108, 108, 111] ++ [0] [104, 101, 108, 108, 111, 0] 

you can read more char lists here


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -