Is there a way to import record definitions in the iex shell for pretty printing (similar to the rr
command in the erl
shell)? This would be very helpful when calling Erlang modules that return records.
IO.inspect with the pretty option set to true?
Could you elaborate on this?
iex(1)> defmodule T do
...(1)> require Record
...(1)> Record.defrecord(:t, [:a, :b, :c])
...(1)> end
iex(2)> require T
T
iex(3)> T.t(a: 1)
{:t, 1, nil, nil}
iex(4)> T.t(a: 1) |> IO.inspect(pretty: true)
{:t, 1, nil, nil}
{:t, 1, nil, nil}
There’s no difference in formatting the output to show record field names and values.
How about when using tools like :recon_trace.calls({module, function, :_}, 1)
- their output is sent to the shell process which prints data in the iex terminal. In case of the Erlang shell, the shell process does the nice formatting of records behind the scene, which is what I am after with iex
.
I don’t think records specifically can be pretty printed, but GitHub - redink/extrace: Elixir wrapper for Recon Trace. does translate trace results to elixir syntax instead of erlang syntax.
I think for interoperability with Erlang, implementing the rr()
, rd()
, rl()
, rf()
, and rp()
in the Elixir shell would really be helpful. Unfortunately extrace
doesn’t fill that gap.