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

Add doctest example for fill! #19422

Merged
merged 2 commits into from
Dec 25, 2016
Merged

Add doctest example for fill! #19422

merged 2 commits into from
Dec 25, 2016

Conversation

kshyatt
Copy link
Contributor

@kshyatt kshyatt commented Nov 25, 2016

No description provided.

@kshyatt kshyatt added the docs This change adds or pertains to documentation label Nov 25, 2016
2×3 Array{Float64,2}:
2.0 2.0 2.0
2.0 2.0 2.0
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! Two thoughts: Perhaps suppress the output of A = zeros(2,3) for compactness? Perhaps also add examples for the two trip hazards mentioned in the docstring? Best!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like showing the output of zeros just so people can see that fill! actually does something, especially since it's an early docstring in stdlib.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cheers, fair enough :).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also looked into adding the examples for objrefs and eval-once but it makes the docstring super long. I think it's ok to leave those un-exampled for now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about demos along these lines? Too long? Best!

julia> fill!(Vector{Int}(3), rand(Int))
3-element Array{Int64,1}:
 -7884629895546034086
 -7884629895546034086
 -7884629895546034086

julia> a = [1, 1, 1]; A = fill!(Vector{Vector{Int}}(3), a); a[1] = 2; A
3-element Array{Array{Int64,1},1}:
 [2,1,1]
 [2,1,1]
 [2,1,1]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want to use rand in doctests.

Copy link
Member

@Sacha0 Sacha0 Nov 26, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! An alternative for that demo:

julia> x = 0; f() = (global x += 1; x); fill!(Vector{Int}(3), f())
 1
 1
 1

@kshyatt
Copy link
Contributor Author

kshyatt commented Dec 24, 2016

Added @Sacha0's great suggestions, this was a really easy rebase.

@tkelman tkelman merged commit 4793e88 into master Dec 25, 2016
@tkelman tkelman deleted the ksh/filltest branch December 25, 2016 07:38
Shade5 pushed a commit to Shade5/julia that referenced this pull request Dec 27, 2016
* Add doctest example for fill!

* Add more doctests
Shade5 pushed a commit to Shade5/julia that referenced this pull request Dec 27, 2016
* Add doctest example for fill!

* Add more doctests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs This change adds or pertains to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants