Have a way to turn off char list printing with inspect
I've been seeing a lot of questions in the IRC channel regarding the "weird" behaviour of inspect([10]) and the likes. It would be good to have an option to inspect to turn off Erlang compatibility in inspect.
Alternatively maybe passing :raw to inspect could disable this behaviour (besides disabling pretty printing of records), though often you want pretty printing of records and no pretty printing of char lists (i.e. you want pure Elixir mode).
:raw was originally just about records. Then we changed to show raw keywords lists too. I don't think we should change it to support lists/binaries because that would make :raw less useful. If we are going along this line, I would rather provide another option.
I definitely agree. Maybe have options to turn the specific prettyfications on and off. Something like
inspect([a: 1, b: 'abc'], charlists: :raw, keywords: :pretty) # :pretty is default
# [a: 1, b: [97, 98, 99]]
I'm thinking of the following options:
recordskeywordscharlistsbinariesall(turns all of the above on/off)
With regard to records there are two levels of rawness though as things like HashSet have a custom Inspect implementation and you might want to look at the underlying records without wanting to look at the tuple form of the records.
Reading what I just wrote I do wonder if we're not conflating two concepts: printing the representation of something and printing a pretty version of something. In Python you have __str__ (pretty string form of something) and __repr__ (in theory unambiguous form of something) with __str__ calling __repr__ if no __str__ is defined.
Just thinking out loud. I just have this feeling that inspecting a value as a string is secretly much more complicated than it appears.
I don't think adding a new option, unless we change the default of charlists to be raw, is going to help beginner, because they will face the problem until they know about the option. And if we are changing the default, is it really worthy to have an option to toggle it? I will start a discussion on the mailing list asking people that are interfacing with Erlang in anger if showing lists as charlists are helping them in some situations or not really and then we can act accordingly by just changing the behaviour altogether.