New way to display a range in REPL #13524
Closed
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.
This is the result of a user's forum discussion about ranges. People were unhappy that
0:5orlinspace(1,10,7)does not return a vector, as they wanted. I believe it is sensible for these to berangeobjects (rather than being converted viacollect), but the REPL display could be modified to show what therangeactually looks like. The user probably wants to see some confirmation of what they were thinking, and seeing the definition doesn't help.The proposed solution is to give REPL output more like this:
This is accomplished my overloading writemime (replutil.jl) to respond to
rangeobjects, adding aprint_rangemethod (range.jl) and appropriate unit tests (test/ranges.jl). This affectsdisplay(), but the user can still useshow(1:5)to return the definition1:5. Theprint_rangemethod is based on the existingprint_matrix_row, and so it uses knowledge of screen size to make everything fit in one row, with horizontal dots (ellipsis) where appropriate.Additional edits were made to show.jl, where I added a bunch of comments. I had to learn how
print_matrixworks, and the comments are meant to save time for someone like me, as the code is a bit opaque. There were absolutely no changes to execution of show.jl.A few notes. I decided not to add brackets around the range. Perhaps square brackets would be appropriate, but I felt they were not needed, as a range is not exactly an array. Also, the range is printed as a single row to save vertical screen space. I thought this was acceptable because tuples are also printed across, despite acting somewhat like 1-d arrays, which are kind of "vertical." I would appreciate feedback if there are disagreements about these choices, or about the whole idea of modifying the REPL.