Proposal: Change the Inspect protocol implementation
Adzz opened this issue · comments
When I a Decimal outputted to the console it looks like this:
#Decimal<1>
This is fine and all but makes copy / pasting from the terminal a nightmare as the above isn't valid elixir code. Other structs handle this by having a sigil - Date for example. That means you can output "~D[2020-01-01]"
Would it be possible to change the inspect protocol to instead output this:
Decimal.new("1")
Or have some other way to make this better. I know the idea of a Decimal sigil has been rejected before -is there any movement on that? I know Decimal even uses a sigil in its tests
I am hesitant to add sigils since they are single character can easily create conflicts. If we added sigils when decimal was created we would have probably picked ~d
and ~D
which would have now conflicted with stdlib dates.
I definitely see the value in being able to copy / paste inspected values into an evaluator. I don't know of any other library where inspect returns a function call such as Decimal.new("1")
but I think we should try it here.
Let us know if would you like to send a PR for the change to inspect as Decimal.new("1")
instead of Decimal<1>
.
Nice! I'd be happy to try it for sure.
Hey 👋 Are there any plans to do a release for this?
Elixir 1.14 is moving towards expression-based inspects, so it would be a good time to release this