如何在不修剪的情况下在长列表上使用 IO.inspect?

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

当我这样做时:

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

我只得到第一个项目(这是解决 15 拼图的移动列表),如下所示:

[: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

如何告诉 IO.inspect 不要 trim 列表?有什么办法吗?

有关可用选项的说明,请参阅 Inspect.Opts

  • :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.

因此你可以通过limit: :infinity来打印所有元素:

IO.inspect(list, limit: :infinity)

对于字符串和字符列表,有一个名为 :printable_limit 的特殊选项。这两个选项可以结合使用以确保所有元素都被完整打印。

对于那些需要上述解决方案不适用于字符串的人。

使用printable_limit: integer/:infinity https://hexdocs.pm/elixir/Inspect.Opts.html