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 parens to |> docstring #36155

Merged
merged 2 commits into from
Feb 26, 2022
Merged

Add parens to |> docstring #36155

merged 2 commits into from
Feb 26, 2022

Conversation

jonniedie
Copy link
Contributor

@jonniedie jonniedie commented Jun 5, 2020

It is a common misunderstanding that
data |> x -> f(x) |> g
parses to
data |> (x -> f(x)) |> g
when it actually parses to
data |> x -> (f(x) |> g)
due to |> operator precedence. This can lead to unexpected behavior when using broadcasted pipelining. Using the docstring example with a broadcasted pipeline operator:

julia> [1:5;] .|> x->x^2 |> sum |> inv
5-element Array{Float64,1}:
 1.0 
 0.25
 0.1111111111111111
 0.0625
 0.04

julia> [1:5;] .|> (x->x^2) |> sum |> inv
0.01818181818181818

Having an anonymous function without enclosing parentheses in the docstring for |> may promote this misunderstanding.

@jonniedie jonniedie changed the title Added parens to |> docstring Add parens to |> docstring Jun 5, 2020
@ViralBShah ViralBShah added the docs This change adds or pertains to documentation label Jun 5, 2020
@ViralBShah
Copy link
Member

ViralBShah commented Jun 5, 2020

I feel like it is valuable to add your comment here into the function documentation. Not the broadcasted pipelining - the operator precedence.

Copy link
Member

@vtjnash vtjnash left a comment

Choose a reason for hiding this comment

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

@ViralBShah WDYT?

base/operators.jl Show resolved Hide resolved
base/operators.jl Outdated Show resolved Hide resolved
@vtjnash vtjnash added the forget me not PRs that one wants to make sure aren't forgotten label Apr 20, 2021
@ViralBShah
Copy link
Member

@jonniedie Can you rebase to master, and we can get this merged.

ViralBShah and others added 2 commits February 25, 2022 20:11
Co-authored-by: Jameson Nash <vtjnash@gmail.com>
Co-authored-by: Jameson Nash <vtjnash@gmail.com>
@jonniedie
Copy link
Contributor Author

jonniedie commented Feb 26, 2022

@ViralBShah I... don't know if I actually did that correctly. I've never done this before.

@fredrikekre fredrikekre merged commit 5ac0020 into JuliaLang:master Feb 26, 2022
staticfloat pushed a commit to JuliaCI/julia-buildkite-testing that referenced this pull request Mar 2, 2022
LilithHafner pushed a commit to LilithHafner/julia that referenced this pull request Mar 8, 2022
@DilumAluthge DilumAluthge removed the forget me not PRs that one wants to make sure aren't forgotten label Sep 6, 2022
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.

5 participants