ub4

ub4

The problem with my code is that for x ← list, do: x+5 always returns garbage (e.g., ~c"\a\t\n\f\r"). It seems that all other values work correctly. I have tried this using a MacBook Pro M2 in VSCode and iex. I have tried this multiple times. Below are my tests and results.

iex(1)> list = [2,4,5,7,8]
[2, 4, 5, 7, 8]
iex(2)> for x <- list, do: x+2
[4, 6, 7, 9, 10]
iex(3)> for x <- list, do: x+3
[5, 7, 8, 10, 11]
iex(4)> for x <- list, do: x+4
[6, 8, 9, 11, 12]
iex(5)> for x <- list, do: x+5
~c"\a\t\n\f\r"
iex(6)> for x <- list, do: x+6
[8, 10, 11, 13, 14]
iex(7)> for x <- list, do: x+7
[9, 11, 12, 14, 15]

I’d really appreciate any guidance you can offer. Thanks!

Showing Posts 1 to 3

code-shoily

code-shoily

christhekeele

christhekeele

What you are seeing (the “c” sigil ~c"…") is called a “charlist”. It’s a format used (more in Erlang than Elixir) to encode text: as unicode codepoints in a list.

What is happening is that the numbers you are displaying in a list ([7, 8, 9, 10, 11, 12]) happen to all be printable unicode codepoints. Elixir defaults to displaying these as charlists in case you were intentionally trying to handle unicode data encoded in this format. (The other lists contain numbers that are not printable unicode codepoints, but numbers that represent other non-printable characters like null characters and carriage returns, and so Elixir determines you must not be trying to display the list of numbers as text.)

In this instance, 7 happens to be printable as the unicode “bell noise” character \a, 8 is the tab character \t, etc.

Of course in Elixir, we normally use binary strings, not charlists, for textual data. If you are confident you won’t be using charlists to describe textual data (which is a safe assumption), you can prevent IEX from trying to display lists of numbers as charlists by creating a file called .iex.exs in the root of your project (or in your home directory to apply this to all projects) and instructing it to always inspect things that might be charlists as normal lists of numbers, even if they are all printable unicode codepoints:

# .iex.exs
IEx.configure(
  inspect: [
    charlists: :as_lists,
  ]
)

This will ensure your lists of arbitrary numbers are never interpreted (for display purposes) as textual data. Of course, the data is the same under the covers: [7, 8, 9, 10, 11, 12] = ~c"\a\t\n\f\r" are the same, and evaluate to the same list of numbers. But this will prevent IEX from making the assumption that there might be valuable unicode information in the list worth displaying to the programmer as text.

ub4

ub4 OP

Thanks! That fixed it. I really appreciate your help!

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apz
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews