Skip to content

Conversation

@artkuo
Copy link
Contributor

@artkuo artkuo commented Oct 10, 2015

This is the result of a user's forum discussion about ranges. People were unhappy that 0:5 or linspace(1,10,7) does not return a vector, as they wanted. I believe it is sensible for these to be range objects (rather than being converted via collect), but the REPL display could be modified to show what the range actually 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:

julia> 0:4
5-element UnitRange{Int64}:
 0,1,2,3,4

julia> 0:100
101-element UnitRange{Int64}:
 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,…,89,90,91,92,93,94,95,96,97,98,99,100

julia> linspace(0,2.5,4)
4-element LinSpace{Float64}:
 0.0,0.833333,1.66667,2.5

This is accomplished my overloading writemime (replutil.jl) to respond to range objects, adding a print_range method (range.jl) and appropriate unit tests (test/ranges.jl). This affects display(), but the user can still use show(1:5) to return the definition 1:5. The print_range method is based on the existing print_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_matrix works, 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.

@tkelman
Copy link
Contributor

tkelman commented Oct 10, 2015

I love all the comments, we need way more of those.

Note that the test needs to take into account that Int is Int32 on 32 bit platforms

@tkelman
Copy link
Contributor

tkelman commented Oct 10, 2015

Oh, please reopen this against master. Features should not go to release-0.4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants