-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
New range display2 #13534
New range display2 #13534
Conversation
…s added while trying to figure out print_matrix and related functions.
cf #13524 |
# 1.0,2.0,3.0,…,4.0,5.0,6.0 | ||
# This function is borrowed from print_matrix in show.jl | ||
# It is usually called by writemime (from replutil.jl) | ||
function print_range(io::IO, r::Union{Range,LinSpace}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This Union
is unnecessary (similarly in writemime
, below), because LinSpace <: Range
.
…xported methods such as alignment.
In response to comments, I switched writemime to stringmime in tests, removed the redundant Union{Range,LinSpace}, and changed the code comments I had added into Docstring format. Also, I discovered that Base.print_matrix is slow when displaying large matrices (try Thanks stevengj for suggesting helpful fixes. |
`pre` and `post` characters for each printed row, `sep` separator string between | ||
printed elements, `hdots` string for the horizontal ellipsis. | ||
""" | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docstring is duplicated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't say duplicated, it's just that I'm not a huge fan of f(a, [b, c])
to show optional parameters. I think it's easier for a reader to parse the simpler call first, and then see how additional parameters are added on. If the square brackets are considered the standard, I can switch to that, but otherwise I prefer my docstring.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Look again. You have the whole docstring twice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doh! sorry about that; removed.
Hmm, didn't it used to pass the tests? What changed? |
This is very strange. I deleted the extra docstring, and suddenly it wouldn't compile. I was able to move the docstring below the function definition, and it successfully makes and tests clean. I do not understand why it would work with a double docstring, and not with a single. I have no idea whether the bug was mine or elsewhere, but except for the odd location of the docstring, everything seems to work now. |
@@ -244,6 +244,75 @@ function show(io::IO, r::LinSpace) | |||
print(io, ')') | |||
end | |||
|
|||
# `print_range(io, r)` prints out a nice looking range r in terms of its elements |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't duplicate the docstring in a comment. Just say # See docstring below.
That's very odd. @one-more-minute, could there be a parser/compiler bug here? I don't see how duplicating the docstring could (correctly) change it from failure to success. |
@artkuo, was this the error you were getting?
If so, I'll have a PR to fix this shortly.
When the docstring was duplicated the first docstring was documenting the second one so the function wasn't being documented at all. See #12737. |
Docstrings defined before `==` is available for `Symbol` comparisions causes a build error. Fix by comparing with `===`. Ref: JuliaLang#13534 (comment)
Docstrings defined before `==` is available for `Symbol` comparisons causes a build error. Fix by comparing with `===`. Ref: JuliaLang#13534 (comment)
Revert "Update types.rst"
That was indeed the error. I found out that during the build process, any docstrings in files compiled before operators.jl (line 11) would cause this error. Line 11 reads: |
Probably best to wait for #13602 to be merged, and then put the docstring back before the function, and finally squash the commits. Then I think it should be ready to merge. |
…rap-fix Fix doc bootstrap method error.
Deprecate A_ldiv_B!(SparseMatrixCSC, StridedVecOrMat) thereby fixing #10787
…ructors Make the constructors of Array and SharedArray consistent
…e in REPL. Previous commits squashed, docstring moved back to front, builds and passes tests
You can do |
Docstrings defined before `==` is available for `Symbol` comparisons causes a build error. Fix by comparing with `===`. Ref: #13534 (comment) (cherry picked from commit d8b6a24) ref #13602
This is the result of a user's forum discussion about ranges. People were unhappy that
0:5
orlinspace(1,10,7)
does not return a vector, as they wanted. I believe it is sensible for these to berange
objects (rather than being converted viacollect
), but the REPL display could be modified to show what therange
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 like this:
This is accomplished by overloading writemime (replutil.jl) to respond to
range
objects, adding aprint_range
method (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_range
method 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_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.
This is take 2: Fixed test to allow for 32- or 64-bit systems; changed pull request to base from master