Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Printing of an empty UnitRange at the REPL lacks information #13966

Closed
rfourquet opened this issue Nov 13, 2015 · 13 comments
Closed

Printing of an empty UnitRange at the REPL lacks information #13966

rfourquet opened this issue Nov 13, 2015 · 13 comments
Labels
REPL Julia's REPL (Read Eval Print Loop)

Comments

@rfourquet
Copy link
Member

An empty UnitRange holds more information than the fact that it's empty, this is used with e.g. searchsorted to indicate the "insertion point". The following session leaves to be desired:

julia> searchsorted([1, 3], 2)
0-element UnitRange{Int64}

julia> ans.start
2

Showing instead something like "0-element UnitRange{Int64} 2:1" would help. Actually, I would personally prefer that even a non-empty range is shown like this in compact form (before the list of its values).

I guess this was made in #13615, cc @artkuo .

@nalimilan
Copy link
Member

+1 to also showing the compact form on the first line. After all, that's the only way to recreate the same object via copy/paste at the REPL.

@StefanKarpinski
Copy link
Member

I really hate the new range printing. Anyone have a link to that discussion and PR handy?

@yuyichao
Copy link
Contributor

It was in the first post #13615 (the PR also links the julia-user discussions)

@artkuo
Copy link
Contributor

artkuo commented Nov 13, 2015

That was me, in response to complaints that people wanted to see what's actually in the Range. I agree there's useful info that could be included in first line. What would you say to something like this?

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

Is there any issue with the colons being so close to each other? The standard summary usually has a colon, as does a StepRange or UnitRange.

@StefanKarpinski
Copy link
Member

I think we should print ranges the way we've always printed them. LinSpace can get special treatment. Ot we can just go back to returning an array, I'm really tired of complaints about this.

@artkuo
Copy link
Contributor

artkuo commented Nov 13, 2015

Did you have something specific in mind about how to return an array and still convey Range? The new method was trying to address that. And the previous way of only showing 1:3 or linspace(1,3,3) was what caused a lot of complaints, as people were expecting something more.

A nice thing about AbstractVector is that clever algebras can be implemented, but the uninterested user can remain relatively naive to the underpinnings. At the REPL, the average user may want to see what's in the Range, while some may want to see the definition. I think @rfourquet is right to provide useful info both ways. My question is how to format it, maybe with a comma?

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

julia> 3:2
0-element UnitRange{Int64) 3:2

Is there a mechanism to have REPL options available for the user to set? The equivalent of "format long" in Matlab? REPL behavior can be highly personal, and it might be nice to offer a way for a person to choose, if it doesn't exist already.

@StefanKarpinski
Copy link
Member

Printing 1:3 never received a single complaint, it was only the linspace thing that people don't like. I'm sick of this and ready to just make linspace return and array and get rid of the LinSpace type.

@artkuo
Copy link
Contributor

artkuo commented Nov 13, 2015

@StefanKarpinski I think the LinSpace complaints will go away when people see the REPL behavior return what they expect. Otherwise, it should be relatively transparent to the user with lots of potential benefits. What we are proposing here is to have our cake and eat it too. I'll try to file a PR to give something concrete to discuss and either accept or reject.

@StefanKarpinski
Copy link
Member

How about leaving other ranges the way they were and just printing LinSpace objects like vectors?

@nalimilan
Copy link
Member

Wouldn't that be too inconsistent, only to reduce the surprise for users coming from MATLAB? The different treatment of LinSpace and FloatRange is particularly hard to justify IMHO.

@StefanKarpinski
Copy link
Member

The justification would seem to be that people are freaked out by one and unphased by the other.

@artkuo
Copy link
Contributor

artkuo commented Nov 13, 2015

For reference here's the 0.4 behavior:

julia> 1:3
1:3

julia> 3:2
3:2

julia> linspace(1,3,3)
linspace(1.0,3.0,3)

Here's the discussion that started this.Why not show more info like number of elements, element type, what's inside, etc.?

@JeffBezanson
Copy link
Member

fixed by #15799

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
REPL Julia's REPL (Read Eval Print Loop)
Projects
None yet
Development

No branches or pull requests

7 participants