smetana
How to increase printable_limit from Macro.to_string()?
Hello all,
I need to convert AST with possible long binary to string.
Macro.to_string() uses Inspect and Inspect has the printable_limit option set to 4096 for binaries by default.
I am looking for the way to increase it so binary will not be truncated on to_string()
Thanks,
Serge
Marked As Solved
net
I believe this is already fixed in master. Until that’s released you can do
Macro.to_string(v, fn
node, _ when is_binary(node) -> inspect(node, printable_limit: :infinity)
_, string -> string
end)
Also Liked
michalmuskala
This seems like a bug in Macro.to_string to me - it should print everything out. Could you open a bug report?
mruoss
This is too related to open a new thread. But when posting before, I wasn’t aware that the problem exists only for maps now. It’s basically the same issue but for maps. Opened a GH issue here:
mruoss
Copying over José’s answer for shortcuts:
The difference here is that maps are not valid AST. We fallback to inspect in Macro.to_string for convenience, because the goal of the macro is mostly debugging, but if you returned that from a macro, Elixir would raise accordingly. In any case, it won’t be formatted accordingly. The correct fix is to call
Macro.escapeor build the correct Map ast, as shown in the result ofquote do: %{1 => 2, foo: :bar}|
For me, Macro.escape did the trick:
my_map = Map.new(1..51, &{&1, "value"}) |> Macro.escape()
(quote do: unquote(my_map))
|> Macro.to_string()
|> IO.inspect(printable_limit: :infinity)







