rameshkumar
Inconsistent Enum.map output
Hi, I’m a little dumbfounded with the following iex session that I ran:
iex(7)> Enum.map([4,5,6], &(2 * &1))
'\b\n\f'
iex(8)> Enum.map([1,5,6], &(2 * &1))
[2, 10, 12]
iex(9)> Enum.map([1,2,3], &(2 * &1))
[2, 4, 6]
iex(10)> Enum.map([7,8,9], &(2 * &1))
[14, 16, 18]
iex(11)> Enum.map([4,5,6,7], &(2 * &1))
[8, 10, 12, 14]
iex(12)>
What is special about the list [4,5,6] (see first two lines of code and its output) that the output is entirely different in meaning from the rest? What am I failing to understand here?
Any ideas?
Thank you.
Marked As Solved
chulkilee
[8, 10, 12] == '\b\n\f'
So the value is correct. What’s surprising (to you) is how iex (actually IO.inspect/2 behind the scene) shows the list in that format.
That is because iex treat it as charlist (note it’s with single quote, not double quote)
- https://elixir-lang.org/getting-started/binaries-strings-and-char-lists.html
- https://stackoverflow.com/questions/30037914/elixir-lists-interpreted-as-char-lists
IO.inspect([8, 10, 12])
IO.inspect([8, 10, 12], charlists: :as_lists)
6
Popular in Questions
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
Hi,
is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
Hi, I’m using Ubuntu 18.04 and after updating to OTP-24.0 yesterday i have this warning when I run “mix local.hex”:
14:57:30.512 [warn] ...
New
Hi there, I'm working through my first release with elixir/phoenix. I've built a release with distillery and found that it crashes when I...
New
As a follow up to my earlier question:
I have the code compiling and running but not getting a successful login from the rest server. ...
New
I would like to know what is the best IDE for elixir development?
New
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
Hi guys, i’m new in the Elixir world, and i have to say, that i love it!
i’m having some problem to understand anonymous functions with ...
New
To simplify some tasks at work, I wrote and published this package yesterday. It’s a simple macro that enables Access behaviour on struct...
New
Other popular topics
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]
15:22:35.803 [error] gen_event {lager_file_backend...
New
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode.
The solution seems to be, in a hyphena...
New
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
I tried installing
elixir 1.11.2
erlang 23.3.4
via asdf in my zsh shell. Enabled the versions locally and globally.
When I list them ...
New
Hi all,
I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage.
I'm trying to use Postg...
New
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
by Lance Halvorsen
Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
New
Hi,
I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New







