-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Clarify the use of do block with get! #36511
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
Conversation
| `f()`. Use [`get!`](@ref) to also store the default value in the dictionary. | ||
| This is intended to be called using `do` block syntax | ||
| This is intended to be called using `do` block syntax, when the first argument |
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.
Not sure the extra thing about "longer than one-liner" needs to be added. The example below immediately contradicts it.
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.
Not sure the extra thing about "longer than one-liner" needs to be added.
Maybe just put a reference to do syntax?
Edit: https://docs.julialang.org/en/v1/base/base/#do explained the syntax already.
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.
Or "more-than-trivial throwaway functions". Not sure if that adds clarity or appropriate in the documentation.
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.
Agreed with both comments.
"This is intended to be called using do block syntax that creates an anonymous function for f::Function (see do syntax)?"
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.
Ops, I just wanted to comment.
| `f::Function` of `get!` is longer than one-liner, for readability. | ||
| ```julia | ||
| get(dict, key) do |
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.
Perhaps best to make this into a proper doctest?
|
If anything needs to be done here, I would favor removing the entire "This is intended to be called using do block syntax:" sentence. This is idiomatic Julia, I hope we will not add such a sentence to every function that supports a function as first parameter... Docstrings are not meant to replace the manual, they should be to the point, not bloated with information that belongs elsewhere. |
|
@rfourquet I see your point: the manual is a trove of information and the do-syntax is explained there. On the other hand, adding more information to the docstring will certainly help people who do not read the full manual before using Julia and may point them to the correct section in the manual. A better docstring will also prevent useless posts like mine in discourse that originated this PR. |
I just had a rapid look to this discourse thread, but it seems that if the sentence related to |
|
Would it make sense to leave the example with
And in this context, is it clear from the documentation that |
It looks fine to me to leave the current example. I would also keep it with the
I guess it depends on the audience. It doesn't make sense to compute |
ref: https://discourse.julialang.org/t/dictionary-inverse-and-consolidating/42378/5