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
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service.
Currently when I de...
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 am trying to implement my new.html.eex file to create new posts on my website.
new.html.eex:
<h1>Create Post</h1>
<...
New
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
For example for a current url like
http://localhost:4000/cosmetic/products?_utf8=✓&query=perfume&page=2,
I would like to get:
...
New
Hi,
I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
I'm brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
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
What is the proper way to load a module from a file in to IEX?
In the python world, doing something like this pretty standard:
from ....
New
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
Other popular topics
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
Hello all!
I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
Hello, how can I check the Phoenix version ?
Thanks !
New
After calling mix ecto.create I get this error:
17:00:32.162 [error] GenServer #PID<0.412.0> terminating
** (Postgrex.Error) FATAL...
New
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors:
[WARN] - (starship::utils): Executing command ...
New
lets say i have a sample like
a = 20; b = 10;
if (a > b) do
{:ok, "a"}
end
if (a < b) do
{:ok, b}
end
if (a == b) do
{:ok, "eq...
New
Hi,
I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition)
It’s been a while since we first asked this, I...
New
I had some trouble figuring out how to make many-to-many associations work. Once I got it working, I wrote a blog post. Because I'm a nov...
New
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New







