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

Ambiguous syntax with operator suffixes #28441

Open
perrutquist opened this issue Aug 4, 2018 · 5 comments
Open

Ambiguous syntax with operator suffixes #28441

perrutquist opened this issue Aug 4, 2018 · 5 comments
Labels
breaking This change will break code parser Language parsing and surface syntax

Comments

@perrutquist
Copy link
Contributor

In Julia 0.6, the following is legal syntax:

ᵃx = 3
1+ᵃx # returns 4

But after #22089, it errors with "UndefVarError: +ᵃ not defined", because it parses as 1 +ᵃ x.

One possible remedy would be to deprecate variable names that begin with characters that are allowed as operator suffixes.

Another option would be to require spaces around suffixed operators.

Or do both, with the options of removing the spaces requirement in a later version.

@stevengj stevengj added the parser Language parsing and surface syntax label Aug 4, 2018
@stevengj
Copy link
Member

stevengj commented Aug 4, 2018

To be clear, it is only the letter sub/superscripts that are the problem here; the other operator suffixes are not allowed as the first character of an identifier.

@JeffBezanson
Copy link
Member

This is another case similar to 1.+2. Probably ok to make it an error like we did there. A bit unfortunate though, since superscript letters seem much more useful as part of variable names than on operators.

@StefanKarpinski
Copy link
Member

They're kind of weird as the first character in an identifier. At least in my mind +ᵃ seems more reasonable then ᵃx.

@stevengj
Copy link
Member

stevengj commented Aug 6, 2018

See also #20278 … identifiers starting with superscripts/subscripts aren't that common, but do appear occasionally in mathematics. It wouldn't be a huge loss to lose them in Julia, though, I guess.

@StefanKarpinski
Copy link
Member

We wouldn't necessarily lose them, we would just lose the ability to write +ᵃx without a space to disambiguate +ᵃ x and + ᵃx—which just seems like a necessary disamgibuation anyway given that we want superscripts on operators and as the leading characters of identifiers.

perrutquist added a commit to perrutquist/julia that referenced this issue Aug 8, 2018
This updates the documentation in line with the proposal in JuliaLang#28441 to disallow `+ᵃx`

Ideally, the parser should be updated together with the documentation, but I'm not familiar enough with the parser internals to do that myself.

This is a breaking change, since `+ᵃx` is currently legal syntax. (The way I interpret semantic versioning, the breaking change occurs when the documentation is updated. If the parser is later updated to work in accordance with the documentation, then that would technically be a bugfix, and wouldn't have to wait until the next major release. In practice though, people will be upset if code that was working in 1.0 suddenly stops working in 1.x.)
@JeffBezanson JeffBezanson added the breaking This change will break code label Sep 18, 2018
ViralBShah pushed a commit that referenced this issue May 11, 2020
* Documentation of amiguous syntax, operator suffix

This updates the documentation in line with the proposal in #28441 to disallow `+ᵃx`

Ideally, the parser should be updated together with the documentation, but I'm not familiar enough with the parser internals to do that myself.

This is a breaking change, since `+ᵃx` is currently legal syntax. (The way I interpret semantic versioning, the breaking change occurs when the documentation is updated. If the parser is later updated to work in accordance with the documentation, then that would technically be a bugfix, and wouldn't have to wait until the next major release. In practice though, people will be upset if code that was working in 1.0 suddenly stops working in 1.x.)

* fix whitespace

Co-authored-by: Kristoffer Carlsson <[email protected]>
Roger-luo pushed a commit to Roger-luo/julia that referenced this issue May 14, 2020
* Documentation of amiguous syntax, operator suffix

This updates the documentation in line with the proposal in JuliaLang#28441 to disallow `+ᵃx`

Ideally, the parser should be updated together with the documentation, but I'm not familiar enough with the parser internals to do that myself.

This is a breaking change, since `+ᵃx` is currently legal syntax. (The way I interpret semantic versioning, the breaking change occurs when the documentation is updated. If the parser is later updated to work in accordance with the documentation, then that would technically be a bugfix, and wouldn't have to wait until the next major release. In practice though, people will be upset if code that was working in 1.0 suddenly stops working in 1.x.)

* fix whitespace

Co-authored-by: Kristoffer Carlsson <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking This change will break code parser Language parsing and surface syntax
Projects
None yet
Development

No branches or pull requests

4 participants