Default to short printing for REPL#168
Open
Keno wants to merge 1 commit into
Open
Conversation
The printing choices in this package are somewhat non-standard
with respect to how Base defines printing, though that is
probably Base's fault for not documenting how these are
supposed to be used properly. In particular, this package
uses the :compact switch to decide between a parseable,
verbose printing and a compact, human-readable printing.
However, these are orthogonal concepts, and the :compact
switch isn't really supposed to switch the parsability.
Parsability vs non-parsibility is the distinction between
`show(io::IO, x)` (parseable) and `show(io::IO, MIME"text/plain"(), x)`
(non-parseable, pretty for humans). The latter is also
what is used for display in REPL contexts whereas the former
is used for repr.
I would like to suggest that the REPL printing should also
default to the human-readable version. For example, I
wanted to use intervals of units in a package, but the
default output looks very scary for first time Julia users:
```
julia> using Intervals, Unitful
julia> 1dB..2dB
Interval{Gain{Unitful.LogInfo{:Decibel, 10, 10}, :?, Int64}, Closed, Closed}(1 dB, 2 dB)
```
Admittedly that is mostly because of the scary Unitful type,
but still. We have better printing, why not use it.
```
julia> 1dB..2dB
[1 dB .. 2 dB]
```
Keno
added a commit
to Keno/Intervals.jl
that referenced
this pull request
Jul 10, 2021
This is sort of an expansion of invenia#168. There I tried to keep the PR fairly minimal to only fix the specific case that was bothering me. Here I try a more extensive set of changes to show some options of what might be possible. Some subset of these may be interesting, so I'm opening this for discussion with the maximum set of possible changes and we can discuss from there. First things first, here's some demo printing: ``` julia> a = Interval{Closed, Open}(DateTime(2013, 2, 13), DateTime(2013, 2, 13, 1)) [2013-02-13T00:00:00, 2013-02-13T01:00:00) julia> show(a) Interval{Closed,Open}(DateTime("2013-02-13T00:00:00"), DateTime("2013-02-13T00:00:00")) julia> show(IOContext(stdout, :compact=>true), a) i`[DateTime("2013-02-13T00:00:00"),DateTime("2013-02-13T01:00:00"))` julia> i`[DateTime("2013-02-13T00:00:00"),DateTime("2013-02-13T01:00:00"))` [2013-02-13T00:00:00, 2013-02-13T01:00:00) julia> const dB = Unitful.dB dB julia> 1 dB .. 2 dB 1 dB .. 2 dB julia> i`(1dB, 2dB]` (1 dB, 2 dB] ``` The most obvious change, is probably the introduction of the i_cmd macro that parses back the short interval syntax and is used for compact, parseable print. Here's the feature highlights of this scheme: - Compact printing is changed to use the unicode double-wide brackets, to distinguish it from ascii brackets, which already have a different meaning - `show(::IO, x::Interval)` is always parseable, both in compact mode and in non-compact mode. Note that the compact interval printing changed from using `..` to `,`. This is to clarify the parsing rules inside the macro. In particular, other than the first and last character, the macro uses tuple parsing rules, so you can do things like: ``` julia> i`(now(), now()+Hour(1)]` (2021-07-10T02:51:37.780, 2021-07-10T03:51:37.780] ``` - The i-macro parses both ASCII and double-wide brackets as interval bounds - The parseable and non-parseable printing now generally only differs in the printing or non-printing of the i-macro. This is quite useful to get something parseable back from an interval that was printed in non-parseable context. - Closed intervals have special printing using the `..` operator to make the output match the input syntax. Of course they can also be constructed using the i-macro (but will still be printed as `..`). - Even for non-compact, parseable prinitng, the long type parameter is dropped, in favor of only showing the Open/Closed setting, since the type should be redunant with the parsing of the bounds being printed. As I said, several of these are independent, so we might only want a subset of these, but I thought, I'd present it as one big thing. This doesn't have any doc(test) changes yet, since I figure things will change, and I didn't want to bother doing that twice :).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The printing choices in this package are somewhat non-standard
with respect to how Base defines printing, though that is
probably Base's fault for not documenting how these are
supposed to be used properly. In particular, this package
uses the :compact switch to decide between a parseable,
verbose printing and a compact, human-readable printing.
However, these are orthogonal concepts, and the :compact
switch isn't really supposed to switch the parsability.
Parsability vs non-parsibility is the distinction between
show(io::IO, x)(parseable) andshow(io::IO, MIME"text/plain"(), x)(non-parseable, pretty for humans). The latter is also
what is used for display in REPL contexts whereas the former
is used for repr.
I would like to suggest that the REPL printing should also
default to the human-readable version. For example, I
wanted to use intervals of units in a package, but the
default output looks very scary for first time Julia users:
Admittedly that is mostly because of the scary Unitful type,
but still. We have better printing, why not use it. After this PR,
the compact printing is used at the REPL: