How to use IO.inspect on a long list without trimming it?

ItsASecret picture ItsASecret · Apr 10, 2015 · Viewed 14.3k times · Source

When I do:

IO.inspect [:right, :top, :left, ...very_long_list]

I only get the first items (it's a list of moves to solve a 15-puzzle) like this:

[:right, :top, :left, :bot, :bot, :left, :top, :top, :right, :right, :bot,
  :left, :bot, :left, :top, :right, :bot, :right, :top, :top, :left, :bot,
  :left, :top, :right, :right, :bot, :bot, :left, :top, :top, :left, :bot,
  :right, :top, :right, :bot, :left, :left, :top, :right, :bot, :right, :top,
  :left, :left, :bot, ...] # => See the '...'
                                instead, I would like 
                                to get the complete list

How can I tell IO.inspect to not trim the list? Is there an option or something?

Answer

Patrick Oscity picture Patrick Oscity · Apr 10, 2015

See Inspect.Opts for a description of the available options:

  • :limit - limits the number of items that are printed for tuples, bitstrings, maps, lists and any other collection of items. It does not apply to strings nor charlists and defaults to 50. If you don't want to limit the number of items to a particular number, use :infinity.

Thus you can pass limit: :infinity to print all elements:

IO.inspect(list, limit: :infinity)

For strings and charlists there is a special option called :printable_limit. Both of these options can be combined to ensure that all elements are fully printed.