Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enum.chunk_every/2 strange results #7260

Closed
pbudzik opened this issue Jan 26, 2018 · 5 comments
Closed

Enum.chunk_every/2 strange results #7260

pbudzik opened this issue Jan 26, 2018 · 5 comments

Comments

@pbudzik
Copy link

pbudzik commented Jan 26, 2018

Environment

  • Erlang/OTP 20 [erts-9.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Elixir 1.7.0-dev (97cf609) (compiled with OTP 20)

  • Operating system: MacOS Sierra

Current behavior

x = Enum.chunk_every([9, 9, 1, 0, 0], 1)
IO.inspect(x)

['\t', '\t', [1], [0], [0]]

Expected behavior

[[9],[9], [1], [0], [0]]

@wojtekmach
Copy link
Member

note:

iex> [[9],[9], [1], [0], [0]]
['\t', '\t', [1], [0], [0]]

iex> [9]
'\t'

so nothing to do with chunk_every. Elixir attempts to print this as a list of characters, see iex> i [9] for more information.

@pbudzik
Copy link
Author

pbudzik commented Jan 26, 2018 via email

@wojtekmach
Copy link
Member

wojtekmach commented Jan 26, 2018

iex> IO.inspect [9], charlists: :as_lists
[9]
'\t'

note this prints what you'd expect, but returns the default representation. If you need to return a string you can do:

iex> inspect [9], charlists: :as_lists
"[9]"

This is documented in https://hexdocs.pm/elixir/IO.html#inspect/2, https://hexdocs.pm/elixir/Inspect.Opts.html

@michalmuskala
Copy link
Member

See a good explanation here https://github.com/elixir-lang/elixir/wiki/FAQ#4-why-is-my-list-of-integers-printed-as-a-string For the reasons behind this design, look at this mailing list thread https://groups.google.com/forum/#!msg/elixir-lang-talk/0xxH9HxdQnU/LHgK8elhEQAJ

@pbudzik
Copy link
Author

pbudzik commented Jan 26, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants