josevalim

josevalim

Creator of Elixir

Convert 'charlists' into ~c"charlists"

Hi everyone,

We are considering deprecating 'charlists' in Elixir in favor of ~c"charlist". In many languages, 'foobar' is equivalent to "foobar", that’s not the case in Elixir and we believe it leads to confusion. If we were to deprecate this functionality, users would get a warning/error upfront about the usage of single-quotes.

The first step in this journey is to change the formatter to rewrite 'charlist' into ~c"charlist". This will basically make the migration painless for most developers.

With this in mind, @sabiwara has submitted an awesome PR that implements this change in the Elixir codebase. Perhaps, more importantly, he has also simulated PRs to important projects to access the impact of this change. Here they are:

As you can see, the changes are minimal to most projects, including postgrex and mint which integrate with OTP libraries. So from a compatibility point of view, this change is relatively straight-forward.

However, should we go ahead with this change? There would be two reasons for such:

  1. If single quotes raised/warned in the future, would that lead to better learning and user experience?

  2. If [97, 98, 99] prints as ~c"abc" in IEx instead of 'abc', is that more, less, or equally confusing? (let’s assume for now that we will either print one or the other, in order to avoid side-tracking the discussion)

Thoughts are welcome!

Most Liked

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

I can count on one hand the number of times when I wanted a list of printable ints to be shown as a charlist in the ~7 years I’ve been doing Elixir. Also in that time I’ve answered why it does that countless times to new people and in not one of those cases were they interacting with Erlang and needed it to be printed as text. I think the time has come to legitimately question whether this should still be the default given how easy it is to opt in to the behavior.

Love the change.

21
Post #6
olivermt

olivermt

A thousand times yes, also for noobs trying to speak to erlang libs.

Eiji

Eiji

Amazing! :heart:

Definitely!

Personally I would like to vote for ~c(abc) instead. This would make many beginners think that ~c is “some kind of function”, so significant % of those should take a look at Kernel documentation at start before asking on forum/slack etc. sigil_c documentation would be then a “core/starting point of understanding the charlists”.

I believe we need to enhance said sigil_c documentation a lot. Even if it would not describes charlists in this @doc it still should point to a separate guide describing “what and why” is it.

Last Post!

Eiji

Eiji

I would say follow Elixir core if you are not sure what to do …

iex> inspect ~c"test"
"~c\"test\""

The custom inspect protocol implementations can use Any implementation to reuse a default Inspect logic.

Where Next?

Trending in Proposals Top

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
kip
Localize is the next generation localisation library for Elixir. Think of it as ex_cldr version 3.0. The first version will be released ...
New
webofbits
Squid Mesh is an open source workflow automation runtime for Elixir applications. It is aimed at Phoenix and OTP apps that want to defin...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
kip
In 2021 I started a new library called Tempo with the objective of modelling time as a set of intervals - not as instants. In 2022 I gave...
New

We're in Beta

About us Mission Statement