renanmuniz

renanmuniz

[newbie here] Strange caracter while using Enum.chunk_every command in iex

Hi people!
I’ve just started learning Elixir this week.

I executed this command in iex and the console output was really strange, could anyone tell me why?

Command:

Enum.chunk_every([1,2,3,4,5,6,7,8,9,10,11,12,13,14], 2)

Return:

[[1, 2], [3, 4], [5, 6], ~c"\a\b", ~c"\t\n", ~c"\v\f", [13, 14]]

What happened to the numbers 7,8,9,10,11 and 12?

Thank you all and have a great day!

Marked As Solved

shawn_leong

shawn_leong

Hey @renanmuniz,

What’s happening is that [7,8], [9,10], [11, 12] are being interpreted as Charlists.

A charlist is a list of integers where all the integers are valid code points.

To see it as non-charlists, you can try piping it the result of your Enum.chunk_every/2 into an inspect/2 function.

inspect(result, charlists: :as_list)

Also Liked

LostKobrakai

LostKobrakai

If you’re interested in the underlying integer values, yes. The problem is that erlang (being the system underlying elixir) does use charlists for text, which you generally also want to be able to read (and not see a list of numbers). Therefore elixir uses a heuristic to figure out which one you might be interested in. That heuristic is imperfect, but better than not having it.

You can find that discussed more elaborately in the docs: List — Elixir v1.16.1

smathy

smathy

*inspect: [charlists: :as_list]

dimitarvp

dimitarvp

Yes, kind of. Though in real production systems you want logging and telemetry traces / spans.

As for development environment, you can just create the file .iex.exs in your project’s root directory and put this there:

IEx.configure(inspect: [charlists: :as_list])

And you’ll have that behaviour for your each local iex session.

dimitarvp

dimitarvp

Thanks, corrected.

dimitarvp

dimitarvp

Because only those are printable (well, in this case they are escape characters for whitespaces but you get the idea).

Where Next?

Popular in Questions Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
Brian
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
dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
hpopp
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
jc00ke
Expanding on this topic: https://forum.elixirforum.net/t/map-typespec-question/19217 Let’s say I have a map with required and optional k...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

Other popular topics Top

vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
rms.mrcs
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
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
baxterw3b
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
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New

We're in Beta

About us Mission Statement