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

unary operators eat function call parentheses when argument is a tuple #12755

Closed
eschnett opened this issue Aug 22, 2015 · 7 comments
Closed
Labels
parser Language parsing and surface syntax

Comments

@eschnett
Copy link
Contributor

This is Julia 0.4-dev in the Jupyter REPL.

This calls f with two arguments: f(1,2)
This calls f with one argument: f((1,2)) (the argument is a tuple).
This calls + with two arguments: +(1,2)
But this doesn't work: +((1,2)) -- it still calls + with two arguments instead of a tuple. This is very counter-intuitive, and I argue it is wrong.

Work-arounds are this: (+)((1,2)) (put operator into parenthesis) or this: +((1,2),) (enforce a single-argument function call via a trailing comma).

(This trailing-comma syntax is documented for tuples; is it also intended and/or documented for function calls?)

The same issue exists for -, !, and ~.

@yuyichao yuyichao added the parser Language parsing and surface syntax label Aug 22, 2015
@eschnett
Copy link
Contributor Author

Here is a test case: Compare the values of

:( (+)((1,2)) ) |> string

and

:( (+)((1,2)) ) |> string |> parse |> string

which differ, i.e. string and parse disagree about the meaning of this construct.

@JeffBezanson
Copy link
Sponsor Member

Yes, I think this can/should be fixed.

timholy added a commit that referenced this issue Aug 23, 2015
@mschauer
Copy link
Contributor

@timholy What was the intention of the revert, should this be reopened?

@KristofferC
Copy link
Sponsor Member

@mschauer #12771

@mschauer
Copy link
Contributor

Thanks.

@JeffBezanson JeffBezanson reopened this Aug 26, 2015
@JeffBezanson JeffBezanson changed the title Unary operators eat function call parentheses unary operators eat function call parentheses when argument is a tuple Aug 26, 2015
@stevengj
Copy link
Member

stevengj commented Mar 2, 2021

Seems be fixed nowadays:

julia> +((1,2))
ERROR: MethodError: no method matching +(::Tuple{Int64,Int64})
Closest candidates are:
  +(::Any, ::Any, ::Any, ::Any...) at operators.jl:538
  +(::Pkg.Resolve.FieldValue, ::Pkg.Resolve.FieldValue) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.5/Pkg/src/Resolve/fieldvalues.jl:43
  +(::Float32, ::Float32) at float.jl:400
  ...
Stacktrace:
 [1] top-level scope at REPL[13]:1

@stevengj stevengj closed this as completed Mar 2, 2021
@mschauer
Copy link
Contributor

mschauer commented Mar 2, 2021

Reference: #26154

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
parser Language parsing and surface syntax
Projects
None yet
Development

No branches or pull requests

6 participants