Elixir: Support a :label option in IO.inspect/2

Created on 15 Jul 2016  路  7Comments  路  Source: elixir-lang/elixir

As discussed in this thread in the elixir-lang-core mailing list.

IO.inspect/2 will now accept a :label option (a binary) to inspect values with a small label before:

iex> IO.inspect([1, 2, 3])
[1, 2, 3]
[1, 2, 3]
iex> IO.inspect([1, 2, 3], label: "a list")
a list: [1, 2, 3]
[1, 2, 3]

The return value of IO.inspect/2 will remain unchanged.

@michalmuskala is working on this.

I wonder, maybe :label is a better name for this option? :tag looks a bit too generic maybe 馃槙 We went with :label :)

Elixir Enhancement Starter

Most helpful comment

I think we've got more votes for :label then? 馃槃 @josevalim what shall we do? :)

All 7 comments

I like tag because it's short, which is important in case of a debugging utility.

I think two characters are still very ok though, with more clarity that this is just a visual thing (tag always makes me think of more complicated/general stuff). Let's wait for other opinions? 馃槂

:+1: for tag.

I really like :label (we also refer to such thing as label in ExUnit.Formatter code). :bowtie:

I prefer :label, elixir uses tag a lot in different context than "Marking stuff". (in 'ExUnit' like example).

I think we've got more votes for :label then? 馃槃 @josevalim what shall we do? :)

:label is fine so we don't further overload :tag.

Was this page helpful?
0 / 5 - 0 ratings