0

I was running through some Elixir Koans and came across the following:

  think "taking some items the other way" do
    numbers = 1..10
    assert Enum.take(numbers, -2) == __?
  end

After spending a lot of time on this I finally looked at it in iex and I get:

'\t\n'

After more experimentation:

Enum.take(numbers, -4) == '\a\b\t\n'
Enum.take(numbers, -5) == [6, 7, 8, 9, 10]

Why does this print out ascii sometimes and the list I'm expecting other times? What happens at 7?

Peer Stritzinger
  • 8,232
  • 2
  • 30
  • 43
ChrisBarthol
  • 4,871
  • 2
  • 21
  • 24

1 Answers1

2

From Elixir FAQ

Pretty-printing of lists is done by using Erlang's native function. It is designed to print lists as strings when all elements of the list are valid ASCII codes.

At 7 you have BEL '\a' (the a is for 'alert' AFIAK)

At 6 you have ACK which apparently doesn't have a printable representation

Josh Petitt
  • 9,371
  • 12
  • 56
  • 104