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

const keyword and multiple assignment #7319

Closed
fxbrain opened this issue Jun 19, 2014 · 6 comments
Closed

const keyword and multiple assignment #7319

fxbrain opened this issue Jun 19, 2014 · 6 comments

Comments

@fxbrain
Copy link

fxbrain commented Jun 19, 2014

Hello.

This seems to be a common scheme and is used in several packages e.g. Datetime, IJulia/stdio etc.

const one, two, three = 1, 2, 3

This is giving now an error: ERROR: syntax: expected assignment after "const"

I presume something goes wrong in scheme parser/lexer.

Thanks in advance.

P.S.: This is my versioninfo:

Julia Version 0.3.0-prerelease+3768
Commit 135f2fb (2014-06-19 15:14 UTC)
Platform Info:
    System: Linux (x86_64-linux-gnu)
   CPU: Intel(R) Celeron(R) 2955U @ 1.40GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY)
  LAPACK: libopenblas
  LIBM: libopenlibm
@mbauman
Copy link
Member

mbauman commented Jun 19, 2014

This was just changed today (135f2fb) to make it more consistent with the global syntax. See #7314.

@lendle
Copy link
Contributor

lendle commented Jun 19, 2014

Assignment without const is still inconsistent:

julia> a=1, b=2
ERROR: syntax: invalid assignment location "1"

julia> global a=1, b=2
2

julia> c,d = 3,4
(3,4)

julia> global c,d = 3,4
ERROR: syntax: invalid syntax in "global" declaration

@fxbrain
Copy link
Author

fxbrain commented Jun 19, 2014

i have the feeling that this change was made maybe too fast.

something like this, for instance, is very common:

const read_stdin, write_stdin = redirect_stdin()

so. using multiple assignment with const does force you to explicitly
declare the tuple:

const (read_stdin, write_stdin) = redirect_stdin()

and without:

read_stdin, write_stdin = redirect_stdin()

well, i don't know, but does this look consistent?

@JeffBezanson
Copy link
Member

I don't think we can have it both ways; either global, const, and local use a=1, b=2 syntax, or a,b = 1,2 syntax. The reason I used the first one is that some variables are just declared but not initialized, e.g. global a, b=1, c declares three global variables but only b is initialized.

@JeffBezanson
Copy link
Member

Ok, I didn't intend this to be such a breaking change, so I think I will revert that commit.

@StefanKarpinski
Copy link
Member

It's unfortunate that bare assignments and qualified assignments are different like this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants