Hi,
while executing this list. insert_at , based on the input list the result are getting varied
List.insert_at([], -1, 65) returns ‘A’ instead of returning [65]
List.insert_at([0], -1, 65) returns [0, 65]
Thanks in advance
Thulasi
Hi,
while executing this list. insert_at , based on the input list the result are getting varied
List.insert_at([], -1, 65) returns ‘A’ instead of returning [65]
List.insert_at([0], -1, 65) returns [0, 65]
Thanks in advance
Thulasi
In ASCII capital letter A is number 65. If remember correctly in Erlang strings are actually lists so when it’s outputted to console code that converts it to text thinks it’s a Erlang string. If you do inspect(your_value_here, charlists: :as_lists)
it should show correctly.
Edit: In Elixir strings are binaries not charlists like in Erlang.
Thanks a lot
If you’re noticing this behavior in iex, you can configure it to print as a list of integers with:
IEx.configure(inspect: [charlists: :as_lists])
You can put this in an .iex.exs
file at the root of your mix project and it will automatically execute when you run iex
.
Hat tip to this presentation for this and other useful tips!