IO.inspect
has long been my go-to technique for troubleshooting code that isn’t quite working how I would expect. Since the :label
option was added in 1.4, I use that all the time, too. The majority of the time, I use it to inspect one or more variables like so:
IO.inspect(foo, label: "foo")
IO.inspect(bar, label: "bar")
However, I often find my self making simple, dumb mistakes when setting this up, such as copying and pasting a prior IO.inspect
line, but forgetting to update the label, e.g.:
IO.inspect(foo, label: "foo")
IO.inspect(bar, label: "foo") # woops, the output will label this as `foo`, too!
Given how common this pattern is, it would be really nice if there was a function or macro to do this for us. I’m thinking something like:
# inspect each variable in the current scope, labeling each with its name
IO.inspect_vars(:all)
# inspect just the provided variables, labeling each
IO.inspect_vars([foo, bar])
# inspect all variables in the current scope, except the provided ones, labeling each
IO.inspect_vars(except: [foo, bar])
I can also imagine it supporting a label
option, to put a title above the list of variables, in order to distinguish multiple variable reports.
Would others find this as useful as I would? Is there interest in it being added to Elixir?
Thanks!
Myron
--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/fd0d67af-3b5f-4ee9-b067-8b263ccd1666%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to a topic in the Google Groups "elixir-lang-core" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/elixir-lang-core/pzs8FVi7bdM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to elixir-lang-core+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4KSmcNtff772p2vhepaqEHhTMuz0ntMU%2BX8U5L6Mukg3Q%40mail.gmail.com.