elbasti
Hi folks, I’ve been running into some very strange behavior that has me knocking my head against the wall.
If I run the following code:
["42", "12", "15"]
|> Enum.map(&(String.to_integer(&1)))
I get what you’d expect: the list [42, 12, 15]
But if I run this code:
["41", "92", "73", "84", "69"]
|> Enum.map(&(String.to_integer(&1)))
I get this weird string: ~c")\\ITE"
In fact, if I run just this:
["41"]
|> Enum.map(&(String.to_integer(&1)))
I get ~c")"
What on earth is going on?!
I figured “maybe there’s some unicode strageness going on with LiveBook” so I tried it in iex, with the same results:
Trending in Questions
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
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
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
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
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
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
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming












Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
outlog
congrats on reaching this milestone - and completing a major step/rite of passage on your elixir journey - it’s a charlist Binaries, strings, and charlists — Elixir v1.21.0-dev
we have all been there - and gone through the same wtf etc.
mindok
Try this to force lists of integers to display as lists of integers (reference: Inspect.Opts — Elixir v1.12.3):
stevensonmt
That this is not the default is a little crazy to me.
kokolegorille
It is a tribute to the Erlang community
dimitarvp
Yeah, you are basically seeing the runtime trying to be a bit too helpful – if a list of integers looks like a list of printable characters, then the REPL will instead show them as a printable string. The data is still there and is still the same.
If you want to get rid of that behavior in your project, just create an
.iex.exsfile at the root of your project and put this in there:Restart your
iexsession and, et voila:stevensonmt
The problem I run into is that it does not apply to any
IO.inspectcalls within the code. You have to remember to doIO.inspect(number_list_that_isnt_supposed_to_be_chars, charlists: :as_lists)every time you might be faced with this weirdness.Aetherus
I think it’s time to make
charlists: :as_liststo be a default option, and deprecate thecharlists: :inferoption.LostKobrakai
I think that would just surface how often we actually run into charlists when interacting with erlang libraries. E.g. hardly any elixir app doesn‘t use gen_tcp somewhere.
From my personal experience I‘ve been hitting the case of needing to see the underlying list of integers mostly in tests or puzzles, where there is time and opportunity to deal with the printed formatting. Not optimal, but fine.
Interacting with actual charlists on the other hand comes up when you‘re debugging some production issue and trying to dig deeper into some failure, where you don‘t want to deal with first setting up useful formatting rules to be able to understand what the system is trying to provide in information.
fuelen
Hehe
I was right here
Adzz
At least now there is the chance that someone can look up the documentation for the
~csigil. Just because it didn’t happen in this case it does not mean it’s not an improvement.