coen.bakker

coen.bakker

Making list from range fails: Enum.to_list(27..77//5)

Ran into a ranges that refuse to turn into a list. For example the one in line 2.

iex(1)> Enum.to_list(27..77//4)
[27, 31, 35, 39, 43, 47, 51, 55, 59, 63, 67, 71, 75]

iex(2)> Enum.to_list(27..77//5)
'\e %*/49>CHM'

Line 1 gives expected list. Line 2 puzzles me.

Any explanations you can think of? Thank you.

Marked As Solved

msimonborg

msimonborg

It’s a special type of list called a charlist, a list of integers where all the integers are valid code points. The default inspect behavior is to represent such a list as the more “human readable” charlist. You can use the charlists: false option to inspect it as a list of integers.

iex(5)> '\e %*/49>CHM' |> IO.inspect(charlists: false) 
[27, 32, 37, 42, 47, 52, 57, 62, 67, 72, 77]

You can configure the shell to do this by default globally or for certain projects.

More reading:

https://elixir-lang.org/getting-started/binaries-strings-and-char-lists.html

Also Liked

ityonemo

ityonemo

This issue comes up every other week or so on elixir forum, don’t worry. Probably the only way it goes away is if in a future version of elixir they get rid of list-encoding Erlang strings with single quotes, but that’s unlikely to happen unless Erlang makes a massive push to deprecate charlist first.

coen.bakker

coen.bakker

Thank you. I have some reading to do, I see. :nerd_face:

Where Next?

Popular in Questions Top

pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
Phillipp
Hey, I have a NanoPi-M3 and try to install Elixir on their Ubuntu image. I followed the Raspberry Pi installation instructions from the ...
New
chewm
Hi guys, nice to meet you to the whole forum, I’m new here, I’m trying to configure visual studio code for elixir, right now the intellis...
New
sabri
Can someone explain the settings of pool_size of Ecto in config file? and what is the recommend size? Thanks
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New

Other popular topics Top

peerreynders
Manning 2016 Halloween weekend sale via Deal of the Day Friday, October 28 - Half off all MEAPs - code WM102816LT Saturday, October 29 ...
326 29600 154
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
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 35421 110
New
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
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
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New

We're in Beta

About us Mission Statement