-
-
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
Add See also:
, remove description of other functions in base.array.jl
#23789
Conversation
base/array.jl
Outdated
@@ -1080,6 +1080,8 @@ end | |||
Remove an item in `collection` and return it. If `collection` is an | |||
ordered container, the last item is returned. | |||
|
|||
See also: shift!, splice! |
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.
[`shift!`](@ref)
etc. to add links in the HTML documentation and code quote the identifier.
base/array.jl
Outdated
@@ -1080,6 +1080,8 @@ end | |||
Remove an item in `collection` and return it. If `collection` is an | |||
ordered container, the last item is returned. | |||
|
|||
See also: [`shift!`](@ref), [`splice!`](@ref) |
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.
What about push!
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.
Push! adds elements, whereas the other functions remove elements. I think, See also:
-lists should be rather minimal: They reduce the need to search the documentation but it's no replacement for a proper search.
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.
A thesaurus lists both similar words and antonyms for a reason – knowing about push!
is useful if you're looking at pop!
. From push!
you could potentially find all the other element addition functions.
base/array.jl
Outdated
@@ -1147,6 +1149,8 @@ end | |||
|
|||
Remove the first `item` from `collection`. | |||
|
|||
See also: [`pop!`](@ref), [`splice!`](@ref) |
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.
What about unshift!
?
`See also`-Lists now contain up to two related functions and antonym at the end Docs of `append!` were not in line with `prepend!`.
base/array.jl
Outdated
@@ -982,6 +991,10 @@ julia> prepend!([3],[1,2]) | |||
2 | |||
3 | |||
``` | |||
|
|||
Use [`unshift!`](@ref) to add individual items to `collection` which are not already | |||
themselves in another collection. The result is of the preceding example is equivalent to |
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 find the phrase "which are not already themselves in another collection" confusing. I think I know what you are getting at, but I would remove it.
base/array.jl
Outdated
|
||
Use [`unshift!`](@ref) to add individual items to `collection` which are not already | ||
themselves in another collection. The result is of the preceding example is equivalent to | ||
`unshift!([1, 2, 3], 4, 5, 6)`. |
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.
The previous example (prepend!([3],[1,2])
I believe) actually has a different result. And there is a duplicate "is" in the above sentence.
I think the sentence is more clear, with out the "which are not already..." part.
base/array.jl
Outdated
@@ -895,9 +898,8 @@ julia> push!([1, 2, 3], 4, 5, 6) | |||
6 | |||
``` | |||
|
|||
Use [`append!`](@ref) to add all the elements of another collection to |
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.
Please don't change unrelated lines. This applies to other places below.
base/array.jl
Outdated
``` | ||
|
||
Use [`unshift!`](@ref) to add individual items to `collection`. The result of |
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'd rather put this in the "See also" paragraph, rather than after the examples, where people might not find it (examples can be long). No need to refer to a particular example, just say "prepend!(x, y)
is equivalent to...".
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 removed these sentences in favor of a "See also:" entry. We opted against further descriptions in "See also" earlier.
I removed all descriptions of other functions and inserted an entry in `See also:` instead. This is related to my first commits' proposal of using a link-description list as `See also:`. I also removed the redundant description in `splice!` for removing items. I opted to remove it from the single-item method, as a (negative) range is used to remove items.
See also:
to pop!, shift! and splice!See also:
, remove description of other functions in base.array.jl
@@ -916,9 +916,11 @@ function push!(a::Array{Any,1}, @nospecialize item) | |||
end | |||
|
|||
""" | |||
append!(collection, collection2) -> collection. | |||
append!(a::Vector, items) -> collection. |
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.
Why this change?
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.
a
has to be a vector for append!
to work. Of course, items
could stay collection
, but this wording is consistent with the other docstrings. Perhaps collection
would be clearer, though, as items
may be interpreted as several seperate items and append!
expects a collection of items...
julia> append!([1 2 3], 1)
ERROR: MethodError: no method matching append!(::Array{Int64,2}, ::Int64)
You might have used a 2d row vector where a 1d column vector was required.
Note the difference between 1d column vector [1,2,3] and 2d row vector [1 2 3].
You can convert to a column vector with the vec() function.
Closest candidates are:
append!(::Array{T,1} where T, ::Any) at array.jl:637
julia> append!([1,2,3], 1)
4-element Array{Int64,1}:
1
2
3
1
julia> append!([1,2,3], 1, 2)
ERROR: MethodError: no method matching append!(::Array{Int64,1}, ::Int64, ::Int64)
Closest candidates are:
append!(::Array{T,1} where T, ::Any) at array.jl:637
append!(::Array{#s45,1} where #s45, ::AbstractArray{T,1} where T) at array.jl:630
julia> append!([1,2,3], [1 2])
5-element Array{Int64,1}:
1
2
3
1
2
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 change should go to a separate commit or PR, and it should use AbstractVector
. I also wonder whether this isn't on purpose, since non-AbstractVector
collections defined in packages could define methods and it would be silly to repeat the information in another docstring.
base/array.jl
Outdated
# Examples | ||
```jldoctest | ||
julia> prepend!([3],[1,2]) | ||
3-element Array{Int64,1}: | ||
1 | ||
2 | ||
3 | ||
|
||
julia> prepend!([1, 2, 3], [4, 5, 6]) |
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.
What does this extra example show that the one just above doesn't?
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 is a remnant of earlier edits, will remove.
Edit: Done, also removed the duplicate example for append!
base/array.jl
Outdated
@@ -1212,6 +1229,8 @@ end | |||
Remove the item at the given `i` and return the modified `a`. Subsequent items | |||
are shifted to fill the resulting gap. | |||
|
|||
See also: [`splice!`](@ref) |
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.
Maybe also pop!
and unshift!
?
base/array.jl
Outdated
@@ -1316,6 +1335,8 @@ Subsequent items are shifted left to fill the resulting gap. | |||
If specified, replacement values from an ordered | |||
collection will be spliced in place of the removed item. | |||
|
|||
See also: [`pop!`](@ref), [`shift!`](@ref), [`insert!`](@ref) |
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.
Also deleteat!
(i.e. links should generally go both directions, right?).
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.
Yeah, right. I think this would be easier if See also:
lists would be generated automatically from some kind of relation-table.
I left these out, as deleteat!
does not return the removed element, but sure - these are related and should be in See also:
.
#23788