Debugging
IO.inspect
We can use IO.inspect/1 to inspect a string respresentation of a value or expression. In a LiveBook, we’ll see anything we IO.inspect in the top section of the output and the results of the last evaluation in the bottom section.
IO.inspect("I will be printed above the line")
# Will be printed above the line and will also be the
# last evaluated value under the line
IO.inspect(1 + 2)
We can also supply a set of options as a second argument to IO.inspect/2. IO.inspect/1 actually calls IO.inspect/2 but the second argument is defaulted to [].
For example, we can add a label to our inspection result with the label option.
IO.inspect("I have a label", label: "result")
IO.inspect("So do I", label: "another_result")
There are various different options we can use, including an option that allows us to see the binary representation of a given string.
IO.inspect("hello", binaries: :as_binaries)