List printed as String in Elixir

I tried my hand on Enum.map. I found this strange conclusion when I added 100 to all the elements of the list.

Terminal screenshot

Why such a conclusion? It turns out that I get the line when I add 100, but it works fine when I perform another operation. I stumbled a bit, I still had unexpected results.

Screenshot 2

+4
source share
1 answer

The value you see 'efgh'is not a string, but a Char List .

[101, 102, 103, 104] ( ), . e, f, g h ASCII, iex codepoints . (, 0 433, ), .

Elixir :

A char list ( , IEx , - ASCII).


'efgh' [101, 102, 103, 104] Elixir , inspect :

Enum.map([1,2,3,4], &(&1 + 100))
#=> 'efgh'

Enum.map([1,2,3,4], &(&1 + 100)) |> inspect(charlists: :as_lists)
#=> [101, 102, 103, 104]
+7

Source: https://habr.com/ru/post/1659298/


All Articles