markhern
The below code is returning “Here’s my list: efl” for me, substituting the ASCII numeric equivalents for 101, 102, and 108. Does anyone feel that this is a bug that should be reported? If I add a higher number like 4000 to the :top key, then Keyword.get_values() works correctly. Looks like a bug to me. I’m running Elixir 1.10.3.
defmodule Trythis do
def findit(jay) do
hh = Keyword.get_values(jay, :top)
IO.puts("Here's my list: #{IO.inspect(hh)}")
end
end
kl = [top: 101, height: 201, bottom: 22, top: 102, bottom: 40, top: 108]
Trythis.findit(kl)
Trending in Questions
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Hello,
I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind.
However, when I launch mix phx.server, I get an error...
New
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
I’m working on a small exercise involving update_in/3, and I came up with this solution:
data = %{
name: "Periodic Table",
category:...
New
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication):
toke...
New
Is there any way to avoid the Hologram compiler running when using iex? It seems like the front-end code could potentially be disregarded...
New
** (ArgumentError) expected :max_attempts to be a positive integer, got: {:@, [line: 10, column: 19], [{:max_attempts, [line: 10, column:...
New
Other Trending Topics
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
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
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
- #ai
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #metaprogramming
- #hex











Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
dimitarvp
You still have the numbers in place, it’s just that
IO.putsandIO.inspectsee those integers are printable ASCII characters so they choose to print them as characters.If you want it not to do that, try this code:
The original behaviour is not a bug, simply a default convenience which you can opt out from.
NobbZ
It should return
:ok, as thats the only value thatIO.puts/2is able to return.It my print
Here's my list: eflthough. But also it should print'efl', as a sideffect of callingIO.inspect.If you want to display a list of integers always as a list of integers, you can use
List.to_string/1.markhern
Yes, my use of
IO.inspectwas incorrect. But you do see thatKeyword.get_values()is returning chars unless I replace 108 with 400 and then its all numbers as we’d expect. Isn’t this inconsistent?NobbZ
No, it is how inspection works.
Any list that only consist of numbers in “printable” ASCII range (10 to 127 iirc) are inspected as charlist by default.
You still can treat it as list of numbers anywhere, as it is a list of numbers.
It’s just representation, it’s not a change in value or type.
Ps: Treachery of Representation - Hauleth not directly about charlists, but in general the same problem
mudasobwa
markhern
Yes, its just representation but why does
Keyword.get_values(kl,:bottom)return a list of numbers? Its just inconsistent – and doesKeyword.get()ever return chars? This is not the robustness I expect of a mature language. I’m aware that the Elixir type system is different and that this behavior isn’t inconsistent in that light.NobbZ
Both return a list of numbers, which in one case fullfils a given predicate and in one case not.
The predicate is
Enum.all(list_to_inspect, &List.ascii_printable?/1), if this returnstruethen the list is inspected as a charlist, if it returnsfalseit is represented as a list of integers.PS:
Keyword.get/3never returns a “char”, it returns whatever the value is.markhern
To be clear, I want numbers to appear. Unfortunately, even with
charlists: :as_listsI still get ‘efl’ from theIO.inspect(). Are you not getting the same? Is my only option to include a 0 in the list? Why does print formatting have to be so hard – haven’t we already figured this one out (in other languages)?NobbZ
In what exact case?
For me it works…
Where the first line is the actual printed value by
IO.inspectand the second line is the inspection of its returned value.Though if you want to present a list of numbers to a user, you shouldn’t rely on
IO.inspector theInspectprotocol at any time. Its meant for debugging and it might chance how it represents individual values without notice!If you need reliable output use one of the various
to_stringfunctions from the various modules as you need them.markhern
I’m trying to get a numeric list to appear using string interpolation (as in the code of my original post). So, even using the option of
charlists: :as_listsinIO.inspectwill not yield the numeric list I so humbly wish for. WhileIO.inspectreturns the numeric list, it’s printing ‘efl’.