简体   繁体   English

什么是iex相当于rp?

[英]What's iex's equivalent to rp?

In the erlang shell, you can avoid troublesome term truncation with rp . 在erlang shell中,您可以使用rp避免麻烦的术语截断。 What's the most idiomatic way to do this in Elixir? 在Elixir中最常用的方法是什么?

I believe the equivalent would be passing limit: :infinity to Kernel.inspect or IO.inspect : 我相信等效的是传递limit: :infinityKernel.inspectIO.inspect

iex(1)> inspect(Enum.to_list(1..100))
"[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, ...]"
iex(2)> inspect(Enum.to_list(1..100), limit: :infinity)
"[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]"

You can use IO.inspect(..., limit: :infinity) to print the value instead of returning it. 您可以使用IO.inspect(..., limit: :infinity)来打印值而不是返回它。

With IO.inspect / Kernel.inspect the pretty-printing (eg colors) are lost, I prefer to modify the IEx limits: 使用IO.inspect / Kernel.inspect漂亮的打印(例如颜色)会丢失,我更喜欢修改IEx限制:

iex(1)> IEx.configure(inspect: [limit: :infinity, printable_limit: :infinity])
:ok
iex(2)> Enum.to_list(1..100)
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62,
 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82,
 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]

Because this is cumbersome to type (no tab completion), I have these functions in my ~/.iex.exs : 因为输入很麻烦(没有制表完成),我在~/.iex.exs有这些功能:

defmodule IExHelpers do
  def set_inspect_limit(limit \\ 50, printable_limit \\ 4096) do
    IEx.configure(inspect: [limit: limit, printable_limit: printable_limit])
  end
  def unset_inspect_limit() do
    set_inspect_limit(:infinity, :infinity)
  end
end

Use like this: 使用这样:

iex(1)> IExHelpers.unset_inspect_limit()
:ok
iex(2)> Enum.to_list(1..100)                                                  
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62,
 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82,
 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]
iex(3)> IExHelpers.set_inspect_limit()                                        
:ok
iex(4)> Enum.to_list(1..100)          
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
 43, 44, 45, 46, 47, 48, 49, 50, ...]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM