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 
nameIO.inspect_vars(:all)
# inspect just the provided variables, labeling eachIO.inspect_vars([foo, bar])
# inspect all variables in the current scope, except the provided ones, 
labeling eachIO.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 [email protected].
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.

Reply via email to